source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/extract-i18n/ivy-extract-loader.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29const extraction_1 = require("@angular/localize/src/tools/src/extract/extraction");
30const nodePath = __importStar(require("path"));
31function localizeExtractLoader(content, map) {
32 // eslint-disable-next-line @typescript-eslint/no-this-alias
33 const loaderContext = this;
34 const options = this.getOptions();
35 // Setup a Webpack-based logger instance
36 const logger = {
37 // level 2 is warnings
38 level: 2,
39 debug(...args) {
40 // eslint-disable-next-line no-console
41 console.debug(...args);
42 },
43 info(...args) {
44 loaderContext.emitWarning(new Error(args.join('')));
45 },
46 warn(...args) {
47 loaderContext.emitWarning(new Error(args.join('')));
48 },
49 error(...args) {
50 loaderContext.emitError(new Error(args.join('')));
51 },
52 };
53 let filename = loaderContext.resourcePath;
54 const mapObject = typeof map === 'string' ? JSON.parse(map) : map;
55 if (mapObject === null || mapObject === void 0 ? void 0 : mapObject.file) {
56 // The extractor's internal sourcemap handling expects the filenames to match
57 filename = nodePath.join(loaderContext.context, mapObject.file);
58 }
59 // Setup a virtual file system instance for the extractor
60 // * MessageExtractor itself uses readFile, relative and resolve
61 // * Internal SourceFileLoader (sourcemap support) uses dirname, exists, readFile, and resolve
62 const filesystem = {
63 readFile(path) {
64 if (path === filename) {
65 return content;
66 }
67 else if (path === filename + '.map') {
68 return typeof map === 'string' ? map : JSON.stringify(map);
69 }
70 else {
71 throw new Error('Unknown file requested: ' + path);
72 }
73 },
74 relative(from, to) {
75 return nodePath.relative(from, to);
76 },
77 resolve(...paths) {
78 return nodePath.resolve(...paths);
79 },
80 exists(path) {
81 return path === filename || path === filename + '.map';
82 },
83 dirname(path) {
84 return nodePath.dirname(path);
85 },
86 };
87 // eslint-disable-next-line @typescript-eslint/no-explicit-any
88 const extractor = new extraction_1.MessageExtractor(filesystem, logger, {
89 // eslint-disable-next-line @typescript-eslint/no-explicit-any
90 basePath: this.rootContext,
91 useSourceMaps: !!map,
92 });
93 const messages = extractor.extractMessages(filename);
94 if (messages.length > 0) {
95 options === null || options === void 0 ? void 0 : options.messageHandler(messages);
96 }
97 // Pass through the original content now that messages have been extracted
98 this.callback(undefined, content, map);
99}
100exports.default = localizeExtractLoader;
Note: See TracBrowser for help on using the repository browser.