1 | (function (factory) {
|
---|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
3 | var v = factory(require, exports);
|
---|
4 | if (v !== undefined) module.exports = v;
|
---|
5 | }
|
---|
6 | else if (typeof define === "function" && define.amd) {
|
---|
7 | define("@angular/compiler-cli/linker/babel/src/es2015_linker_plugin", ["require", "exports", "tslib", "@babel/types", "@angular/compiler-cli/linker", "@angular/compiler-cli/linker/babel/src/ast/babel_ast_factory", "@angular/compiler-cli/linker/babel/src/ast/babel_ast_host", "@angular/compiler-cli/linker/babel/src/babel_declaration_scope"], factory);
|
---|
8 | }
|
---|
9 | })(function (require, exports) {
|
---|
10 | "use strict";
|
---|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
12 | exports.createEs2015LinkerPlugin = void 0;
|
---|
13 | var tslib_1 = require("tslib");
|
---|
14 | var t = require("@babel/types");
|
---|
15 | var linker_1 = require("@angular/compiler-cli/linker");
|
---|
16 | var babel_ast_factory_1 = require("@angular/compiler-cli/linker/babel/src/ast/babel_ast_factory");
|
---|
17 | var babel_ast_host_1 = require("@angular/compiler-cli/linker/babel/src/ast/babel_ast_host");
|
---|
18 | var babel_declaration_scope_1 = require("@angular/compiler-cli/linker/babel/src/babel_declaration_scope");
|
---|
19 | /**
|
---|
20 | * Create a Babel plugin that visits the program, identifying and linking partial declarations.
|
---|
21 | *
|
---|
22 | * The plugin delegates most of its work to a generic `FileLinker` for each file (`t.Program` in
|
---|
23 | * Babel) that is visited.
|
---|
24 | */
|
---|
25 | function createEs2015LinkerPlugin(_a) {
|
---|
26 | var fileSystem = _a.fileSystem, logger = _a.logger, options = tslib_1.__rest(_a, ["fileSystem", "logger"]);
|
---|
27 | var fileLinker = null;
|
---|
28 | return {
|
---|
29 | visitor: {
|
---|
30 | Program: {
|
---|
31 | /**
|
---|
32 | * Create a new `FileLinker` as we enter each file (`t.Program` in Babel).
|
---|
33 | */
|
---|
34 | enter: function (path) {
|
---|
35 | var _a, _b;
|
---|
36 | assertNull(fileLinker);
|
---|
37 | // Babel can be configured with a `filename` or `relativeFilename` (or both, or neither) -
|
---|
38 | // possibly relative to the optional `cwd` path.
|
---|
39 | var file = path.hub.file;
|
---|
40 | var filename = (_a = file.opts.filename) !== null && _a !== void 0 ? _a : file.opts.filenameRelative;
|
---|
41 | if (!filename) {
|
---|
42 | throw new Error('No filename (nor filenameRelative) provided by Babel. This is required for the linking of partially compiled directives and components.');
|
---|
43 | }
|
---|
44 | var sourceUrl = fileSystem.resolve((_b = file.opts.cwd) !== null && _b !== void 0 ? _b : '.', filename);
|
---|
45 | var linkerEnvironment = linker_1.LinkerEnvironment.create(fileSystem, logger, new babel_ast_host_1.BabelAstHost(), new babel_ast_factory_1.BabelAstFactory(sourceUrl), options);
|
---|
46 | fileLinker = new linker_1.FileLinker(linkerEnvironment, sourceUrl, file.code);
|
---|
47 | },
|
---|
48 | /**
|
---|
49 | * On exiting the file, insert any shared constant statements that were generated during
|
---|
50 | * linking of the partial declarations.
|
---|
51 | */
|
---|
52 | exit: function () {
|
---|
53 | var e_1, _a;
|
---|
54 | assertNotNull(fileLinker);
|
---|
55 | try {
|
---|
56 | for (var _b = tslib_1.__values(fileLinker.getConstantStatements()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
---|
57 | var _d = _c.value, constantScope = _d.constantScope, statements = _d.statements;
|
---|
58 | insertStatements(constantScope, statements);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
---|
62 | finally {
|
---|
63 | try {
|
---|
64 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
---|
65 | }
|
---|
66 | finally { if (e_1) throw e_1.error; }
|
---|
67 | }
|
---|
68 | fileLinker = null;
|
---|
69 | }
|
---|
70 | },
|
---|
71 | /**
|
---|
72 | * Test each call expression to see if it is a partial declaration; it if is then replace it
|
---|
73 | * with the results of linking the declaration.
|
---|
74 | */
|
---|
75 | CallExpression: function (call) {
|
---|
76 | if (fileLinker === null) {
|
---|
77 | // Any statements that are inserted upon program exit will be visited outside of an active
|
---|
78 | // linker context. These call expressions are known not to contain partial declarations,
|
---|
79 | // so it's safe to skip visiting those call expressions.
|
---|
80 | return;
|
---|
81 | }
|
---|
82 | try {
|
---|
83 | var calleeName = getCalleeName(call);
|
---|
84 | if (calleeName === null) {
|
---|
85 | return;
|
---|
86 | }
|
---|
87 | var args = call.node.arguments;
|
---|
88 | if (!fileLinker.isPartialDeclaration(calleeName) || !isExpressionArray(args)) {
|
---|
89 | return;
|
---|
90 | }
|
---|
91 | var declarationScope = new babel_declaration_scope_1.BabelDeclarationScope(call.scope);
|
---|
92 | var replacement = fileLinker.linkPartialDeclaration(calleeName, args, declarationScope);
|
---|
93 | call.replaceWith(replacement);
|
---|
94 | }
|
---|
95 | catch (e) {
|
---|
96 | var node = linker_1.isFatalLinkerError(e) ? e.node : call.node;
|
---|
97 | throw buildCodeFrameError(call.hub.file, e.message, node);
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 | };
|
---|
102 | }
|
---|
103 | exports.createEs2015LinkerPlugin = createEs2015LinkerPlugin;
|
---|
104 | /**
|
---|
105 | * Insert the `statements` at the location defined by `path`.
|
---|
106 | *
|
---|
107 | * The actual insertion strategy depends upon the type of the `path`.
|
---|
108 | */
|
---|
109 | function insertStatements(path, statements) {
|
---|
110 | if (path.isFunction()) {
|
---|
111 | insertIntoFunction(path, statements);
|
---|
112 | }
|
---|
113 | else if (path.isProgram()) {
|
---|
114 | insertIntoProgram(path, statements);
|
---|
115 | }
|
---|
116 | }
|
---|
117 | /**
|
---|
118 | * Insert the `statements` at the top of the body of the `fn` function.
|
---|
119 | */
|
---|
120 | function insertIntoFunction(fn, statements) {
|
---|
121 | var body = fn.get('body');
|
---|
122 | body.unshiftContainer('body', statements);
|
---|
123 | }
|
---|
124 | /**
|
---|
125 | * Insert the `statements` at the top of the `program`, below any import statements.
|
---|
126 | */
|
---|
127 | function insertIntoProgram(program, statements) {
|
---|
128 | var body = program.get('body');
|
---|
129 | var importStatements = body.filter(function (statement) { return statement.isImportDeclaration(); });
|
---|
130 | if (importStatements.length === 0) {
|
---|
131 | program.unshiftContainer('body', statements);
|
---|
132 | }
|
---|
133 | else {
|
---|
134 | importStatements[importStatements.length - 1].insertAfter(statements);
|
---|
135 | }
|
---|
136 | }
|
---|
137 | function getCalleeName(call) {
|
---|
138 | var callee = call.node.callee;
|
---|
139 | if (t.isIdentifier(callee)) {
|
---|
140 | return callee.name;
|
---|
141 | }
|
---|
142 | else if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {
|
---|
143 | return callee.property.name;
|
---|
144 | }
|
---|
145 | else if (t.isMemberExpression(callee) && t.isStringLiteral(callee.property)) {
|
---|
146 | return callee.property.value;
|
---|
147 | }
|
---|
148 | else {
|
---|
149 | return null;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | /**
|
---|
153 | * Return true if all the `nodes` are Babel expressions.
|
---|
154 | */
|
---|
155 | function isExpressionArray(nodes) {
|
---|
156 | return nodes.every(function (node) { return t.isExpression(node); });
|
---|
157 | }
|
---|
158 | /**
|
---|
159 | * Assert that the given `obj` is `null`.
|
---|
160 | */
|
---|
161 | function assertNull(obj) {
|
---|
162 | if (obj !== null) {
|
---|
163 | throw new Error('BUG - expected `obj` to be null');
|
---|
164 | }
|
---|
165 | }
|
---|
166 | /**
|
---|
167 | * Assert that the given `obj` is not `null`.
|
---|
168 | */
|
---|
169 | function assertNotNull(obj) {
|
---|
170 | if (obj === null) {
|
---|
171 | throw new Error('BUG - expected `obj` not to be null');
|
---|
172 | }
|
---|
173 | }
|
---|
174 | /**
|
---|
175 | * Create a string representation of an error that includes the code frame of the `node`.
|
---|
176 | */
|
---|
177 | function buildCodeFrameError(file, message, node) {
|
---|
178 | var filename = file.opts.filename || '(unknown file)';
|
---|
179 | var error = file.buildCodeFrameError(node, message);
|
---|
180 | return filename + ": " + error.message;
|
---|
181 | }
|
---|
182 | });
|
---|
183 | //# sourceMappingURL=data:application/json;base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