@angular/compiler-cli 17.1.0-next.4 → 17.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/{chunk-HQUXRCDO.js → chunk-75SXFAVW.js} +56 -30
- package/bundles/chunk-75SXFAVW.js.map +6 -0
- package/bundles/{chunk-YGXKICXB.js → chunk-AJU3W7PS.js} +93 -10
- package/bundles/chunk-AJU3W7PS.js.map +6 -0
- package/bundles/{chunk-5QWOGIJL.js → chunk-FIHKBAQF.js} +2 -2
- package/bundles/{chunk-EFMKZSXJ.js → chunk-OQ7ITPZT.js} +817 -2
- package/bundles/chunk-OQ7ITPZT.js.map +6 -0
- package/bundles/chunk-Q5Y7HH3O.js +62 -0
- package/bundles/chunk-Q5Y7HH3O.js.map +6 -0
- package/bundles/{chunk-OZXTEOXW.js → chunk-R5FBSX7J.js} +21 -3
- package/bundles/chunk-R5FBSX7J.js.map +6 -0
- package/bundles/{chunk-U4EFDEE4.js → chunk-YS2EFQ7B.js} +94 -102
- package/bundles/chunk-YS2EFQ7B.js.map +6 -0
- package/bundles/index.js +8 -6
- package/bundles/index.js.map +1 -1
- package/bundles/linker/babel/index.js +5 -3
- package/bundles/linker/babel/index.js.map +1 -1
- package/bundles/linker/index.js +2 -3
- package/bundles/private/migrations.js +6 -5
- package/bundles/private/tooling.js +6 -2
- package/bundles/src/bin/ng_xi18n.js +5 -5
- package/bundles/src/bin/ngc.js +5 -5
- package/bundles_metadata.json +1 -1
- package/linker/babel/src/ast/babel_ast_host.d.ts +1 -0
- package/linker/src/ast/ast_host.d.ts +4 -0
- package/linker/src/ast/ast_value.d.ts +8 -1
- package/linker/src/ast/typescript/typescript_ast_host.d.ts +1 -0
- package/linker/src/file_linker/partial_linkers/util.d.ts +1 -1
- package/package.json +2 -2
- package/private/tooling.d.ts +22 -6
- package/src/ngtsc/annotations/directive/index.d.ts +1 -0
- package/src/ngtsc/annotations/directive/src/input_function.d.ts +4 -13
- package/src/ngtsc/annotations/directive/src/shared.d.ts +2 -2
- package/src/ngtsc/annotations/index.d.ts +2 -2
- package/src/ngtsc/diagnostics/src/error_code.d.ts +6 -0
- package/src/ngtsc/transform/index.d.ts +1 -0
- package/src/ngtsc/transform/src/utils.d.ts +1 -1
- package/src/ngtsc/translator/src/api/ast_factory.d.ts +1 -1
- package/src/ngtsc/translator/src/import_manager.d.ts +2 -1
- package/src/ngtsc/typecheck/src/oob.d.ts +3 -3
- package/src/ngtsc/typecheck/src/tcb_util.d.ts +1 -1
- package/src/transformers/{downlevel_decorators_transform → jit_transforms}/index.d.ts +1 -0
- package/src/transformers/jit_transforms/signal_inputs_metadata_transform.d.ts +21 -0
- package/bundles/chunk-EFMKZSXJ.js.map +0 -6
- package/bundles/chunk-HQUXRCDO.js.map +0 -6
- package/bundles/chunk-MFE4YVWE.js +0 -831
- package/bundles/chunk-MFE4YVWE.js.map +0 -6
- package/bundles/chunk-OZXTEOXW.js.map +0 -6
- package/bundles/chunk-U4EFDEE4.js.map +0 -6
- package/bundles/chunk-YGXKICXB.js.map +0 -6
- /package/bundles/{chunk-5QWOGIJL.js.map → chunk-FIHKBAQF.js.map} +0 -0
- /package/src/transformers/{downlevel_decorators_transform → jit_transforms}/downlevel_decorators_transform.d.ts +0 -0
|
@@ -1,831 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {createRequire as __cjsCompatRequire} from 'module';
|
|
3
|
-
const require = __cjsCompatRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AmbientImport,
|
|
7
|
-
ImportFlags,
|
|
8
|
-
NoopImportRewriter,
|
|
9
|
-
Reference,
|
|
10
|
-
assertSuccessfulReferenceEmit
|
|
11
|
-
} from "./chunk-EFMKZSXJ.js";
|
|
12
|
-
|
|
13
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/context.mjs
|
|
14
|
-
var Context = class {
|
|
15
|
-
constructor(isStatement) {
|
|
16
|
-
this.isStatement = isStatement;
|
|
17
|
-
}
|
|
18
|
-
get withExpressionMode() {
|
|
19
|
-
return this.isStatement ? new Context(false) : this;
|
|
20
|
-
}
|
|
21
|
-
get withStatementMode() {
|
|
22
|
-
return !this.isStatement ? new Context(true) : this;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/translator.mjs
|
|
27
|
-
import * as o from "@angular/compiler";
|
|
28
|
-
var UNARY_OPERATORS = /* @__PURE__ */ new Map([
|
|
29
|
-
[o.UnaryOperator.Minus, "-"],
|
|
30
|
-
[o.UnaryOperator.Plus, "+"]
|
|
31
|
-
]);
|
|
32
|
-
var BINARY_OPERATORS = /* @__PURE__ */ new Map([
|
|
33
|
-
[o.BinaryOperator.And, "&&"],
|
|
34
|
-
[o.BinaryOperator.Bigger, ">"],
|
|
35
|
-
[o.BinaryOperator.BiggerEquals, ">="],
|
|
36
|
-
[o.BinaryOperator.BitwiseAnd, "&"],
|
|
37
|
-
[o.BinaryOperator.Divide, "/"],
|
|
38
|
-
[o.BinaryOperator.Equals, "=="],
|
|
39
|
-
[o.BinaryOperator.Identical, "==="],
|
|
40
|
-
[o.BinaryOperator.Lower, "<"],
|
|
41
|
-
[o.BinaryOperator.LowerEquals, "<="],
|
|
42
|
-
[o.BinaryOperator.Minus, "-"],
|
|
43
|
-
[o.BinaryOperator.Modulo, "%"],
|
|
44
|
-
[o.BinaryOperator.Multiply, "*"],
|
|
45
|
-
[o.BinaryOperator.NotEquals, "!="],
|
|
46
|
-
[o.BinaryOperator.NotIdentical, "!=="],
|
|
47
|
-
[o.BinaryOperator.Or, "||"],
|
|
48
|
-
[o.BinaryOperator.Plus, "+"],
|
|
49
|
-
[o.BinaryOperator.NullishCoalesce, "??"]
|
|
50
|
-
]);
|
|
51
|
-
var ExpressionTranslatorVisitor = class {
|
|
52
|
-
constructor(factory, imports, options) {
|
|
53
|
-
this.factory = factory;
|
|
54
|
-
this.imports = imports;
|
|
55
|
-
this.downlevelTaggedTemplates = options.downlevelTaggedTemplates === true;
|
|
56
|
-
this.downlevelVariableDeclarations = options.downlevelVariableDeclarations === true;
|
|
57
|
-
this.recordWrappedNode = options.recordWrappedNode || (() => {
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
visitDeclareVarStmt(stmt, context) {
|
|
61
|
-
var _a;
|
|
62
|
-
const varType = this.downlevelVariableDeclarations ? "var" : stmt.hasModifier(o.StmtModifier.Final) ? "const" : "let";
|
|
63
|
-
return this.attachComments(this.factory.createVariableDeclaration(stmt.name, (_a = stmt.value) == null ? void 0 : _a.visitExpression(this, context.withExpressionMode), varType), stmt.leadingComments);
|
|
64
|
-
}
|
|
65
|
-
visitDeclareFunctionStmt(stmt, context) {
|
|
66
|
-
return this.attachComments(this.factory.createFunctionDeclaration(stmt.name, stmt.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(stmt.statements, context.withStatementMode))), stmt.leadingComments);
|
|
67
|
-
}
|
|
68
|
-
visitExpressionStmt(stmt, context) {
|
|
69
|
-
return this.attachComments(this.factory.createExpressionStatement(stmt.expr.visitExpression(this, context.withStatementMode)), stmt.leadingComments);
|
|
70
|
-
}
|
|
71
|
-
visitReturnStmt(stmt, context) {
|
|
72
|
-
return this.attachComments(this.factory.createReturnStatement(stmt.value.visitExpression(this, context.withExpressionMode)), stmt.leadingComments);
|
|
73
|
-
}
|
|
74
|
-
visitIfStmt(stmt, context) {
|
|
75
|
-
return this.attachComments(this.factory.createIfStatement(stmt.condition.visitExpression(this, context), this.factory.createBlock(this.visitStatements(stmt.trueCase, context.withStatementMode)), stmt.falseCase.length > 0 ? this.factory.createBlock(this.visitStatements(stmt.falseCase, context.withStatementMode)) : null), stmt.leadingComments);
|
|
76
|
-
}
|
|
77
|
-
visitReadVarExpr(ast, _context) {
|
|
78
|
-
const identifier = this.factory.createIdentifier(ast.name);
|
|
79
|
-
this.setSourceMapRange(identifier, ast.sourceSpan);
|
|
80
|
-
return identifier;
|
|
81
|
-
}
|
|
82
|
-
visitWriteVarExpr(expr, context) {
|
|
83
|
-
const assignment = this.factory.createAssignment(this.setSourceMapRange(this.factory.createIdentifier(expr.name), expr.sourceSpan), expr.value.visitExpression(this, context));
|
|
84
|
-
return context.isStatement ? assignment : this.factory.createParenthesizedExpression(assignment);
|
|
85
|
-
}
|
|
86
|
-
visitWriteKeyExpr(expr, context) {
|
|
87
|
-
const exprContext = context.withExpressionMode;
|
|
88
|
-
const target = this.factory.createElementAccess(expr.receiver.visitExpression(this, exprContext), expr.index.visitExpression(this, exprContext));
|
|
89
|
-
const assignment = this.factory.createAssignment(target, expr.value.visitExpression(this, exprContext));
|
|
90
|
-
return context.isStatement ? assignment : this.factory.createParenthesizedExpression(assignment);
|
|
91
|
-
}
|
|
92
|
-
visitWritePropExpr(expr, context) {
|
|
93
|
-
const target = this.factory.createPropertyAccess(expr.receiver.visitExpression(this, context), expr.name);
|
|
94
|
-
return this.factory.createAssignment(target, expr.value.visitExpression(this, context));
|
|
95
|
-
}
|
|
96
|
-
visitInvokeFunctionExpr(ast, context) {
|
|
97
|
-
return this.setSourceMapRange(this.factory.createCallExpression(ast.fn.visitExpression(this, context), ast.args.map((arg) => arg.visitExpression(this, context)), ast.pure), ast.sourceSpan);
|
|
98
|
-
}
|
|
99
|
-
visitTaggedTemplateExpr(ast, context) {
|
|
100
|
-
return this.setSourceMapRange(this.createTaggedTemplateExpression(ast.tag.visitExpression(this, context), {
|
|
101
|
-
elements: ast.template.elements.map((e) => {
|
|
102
|
-
var _a;
|
|
103
|
-
return createTemplateElement({
|
|
104
|
-
cooked: e.text,
|
|
105
|
-
raw: e.rawText,
|
|
106
|
-
range: (_a = e.sourceSpan) != null ? _a : ast.sourceSpan
|
|
107
|
-
});
|
|
108
|
-
}),
|
|
109
|
-
expressions: ast.template.expressions.map((e) => e.visitExpression(this, context))
|
|
110
|
-
}), ast.sourceSpan);
|
|
111
|
-
}
|
|
112
|
-
visitInstantiateExpr(ast, context) {
|
|
113
|
-
return this.factory.createNewExpression(ast.classExpr.visitExpression(this, context), ast.args.map((arg) => arg.visitExpression(this, context)));
|
|
114
|
-
}
|
|
115
|
-
visitLiteralExpr(ast, _context) {
|
|
116
|
-
return this.setSourceMapRange(this.factory.createLiteral(ast.value), ast.sourceSpan);
|
|
117
|
-
}
|
|
118
|
-
visitLocalizedString(ast, context) {
|
|
119
|
-
const elements = [createTemplateElement(ast.serializeI18nHead())];
|
|
120
|
-
const expressions = [];
|
|
121
|
-
for (let i = 0; i < ast.expressions.length; i++) {
|
|
122
|
-
const placeholder = this.setSourceMapRange(ast.expressions[i].visitExpression(this, context), ast.getPlaceholderSourceSpan(i));
|
|
123
|
-
expressions.push(placeholder);
|
|
124
|
-
elements.push(createTemplateElement(ast.serializeI18nTemplatePart(i + 1)));
|
|
125
|
-
}
|
|
126
|
-
const localizeTag = this.factory.createIdentifier("$localize");
|
|
127
|
-
return this.setSourceMapRange(this.createTaggedTemplateExpression(localizeTag, { elements, expressions }), ast.sourceSpan);
|
|
128
|
-
}
|
|
129
|
-
createTaggedTemplateExpression(tag, template) {
|
|
130
|
-
return this.downlevelTaggedTemplates ? this.createES5TaggedTemplateFunctionCall(tag, template) : this.factory.createTaggedTemplate(tag, template);
|
|
131
|
-
}
|
|
132
|
-
createES5TaggedTemplateFunctionCall(tagHandler, { elements, expressions }) {
|
|
133
|
-
const { moduleImport, symbol } = this.imports.generateNamedImport("tslib", "__makeTemplateObject");
|
|
134
|
-
const __makeTemplateObjectHelper = moduleImport === null ? this.factory.createIdentifier(symbol) : this.factory.createPropertyAccess(moduleImport, symbol);
|
|
135
|
-
const cooked = [];
|
|
136
|
-
const raw = [];
|
|
137
|
-
for (const element of elements) {
|
|
138
|
-
cooked.push(this.factory.setSourceMapRange(this.factory.createLiteral(element.cooked), element.range));
|
|
139
|
-
raw.push(this.factory.setSourceMapRange(this.factory.createLiteral(element.raw), element.range));
|
|
140
|
-
}
|
|
141
|
-
const templateHelperCall = this.factory.createCallExpression(
|
|
142
|
-
__makeTemplateObjectHelper,
|
|
143
|
-
[this.factory.createArrayLiteral(cooked), this.factory.createArrayLiteral(raw)],
|
|
144
|
-
false
|
|
145
|
-
);
|
|
146
|
-
return this.factory.createCallExpression(
|
|
147
|
-
tagHandler,
|
|
148
|
-
[templateHelperCall, ...expressions],
|
|
149
|
-
false
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
visitExternalExpr(ast, _context) {
|
|
153
|
-
if (ast.value.name === null) {
|
|
154
|
-
if (ast.value.moduleName === null) {
|
|
155
|
-
throw new Error("Invalid import without name nor moduleName");
|
|
156
|
-
}
|
|
157
|
-
return this.imports.generateNamespaceImport(ast.value.moduleName);
|
|
158
|
-
}
|
|
159
|
-
if (ast.value.moduleName !== null) {
|
|
160
|
-
const { moduleImport, symbol } = this.imports.generateNamedImport(ast.value.moduleName, ast.value.name);
|
|
161
|
-
if (moduleImport === null) {
|
|
162
|
-
return this.factory.createIdentifier(symbol);
|
|
163
|
-
} else {
|
|
164
|
-
return this.factory.createPropertyAccess(moduleImport, symbol);
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
return this.factory.createIdentifier(ast.value.name);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
visitConditionalExpr(ast, context) {
|
|
171
|
-
let cond = ast.condition.visitExpression(this, context);
|
|
172
|
-
if (ast.condition instanceof o.ConditionalExpr) {
|
|
173
|
-
cond = this.factory.createParenthesizedExpression(cond);
|
|
174
|
-
}
|
|
175
|
-
return this.factory.createConditional(cond, ast.trueCase.visitExpression(this, context), ast.falseCase.visitExpression(this, context));
|
|
176
|
-
}
|
|
177
|
-
visitDynamicImportExpr(ast, context) {
|
|
178
|
-
return this.factory.createDynamicImport(ast.url);
|
|
179
|
-
}
|
|
180
|
-
visitNotExpr(ast, context) {
|
|
181
|
-
return this.factory.createUnaryExpression("!", ast.condition.visitExpression(this, context));
|
|
182
|
-
}
|
|
183
|
-
visitFunctionExpr(ast, context) {
|
|
184
|
-
var _a;
|
|
185
|
-
return this.factory.createFunctionExpression((_a = ast.name) != null ? _a : null, ast.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(ast.statements, context)));
|
|
186
|
-
}
|
|
187
|
-
visitArrowFunctionExpr(ast, context) {
|
|
188
|
-
return this.factory.createArrowFunctionExpression(ast.params.map((param) => param.name), Array.isArray(ast.body) ? this.factory.createBlock(this.visitStatements(ast.body, context)) : ast.body.visitExpression(this, context));
|
|
189
|
-
}
|
|
190
|
-
visitBinaryOperatorExpr(ast, context) {
|
|
191
|
-
if (!BINARY_OPERATORS.has(ast.operator)) {
|
|
192
|
-
throw new Error(`Unknown binary operator: ${o.BinaryOperator[ast.operator]}`);
|
|
193
|
-
}
|
|
194
|
-
return this.factory.createBinaryExpression(ast.lhs.visitExpression(this, context), BINARY_OPERATORS.get(ast.operator), ast.rhs.visitExpression(this, context));
|
|
195
|
-
}
|
|
196
|
-
visitReadPropExpr(ast, context) {
|
|
197
|
-
return this.factory.createPropertyAccess(ast.receiver.visitExpression(this, context), ast.name);
|
|
198
|
-
}
|
|
199
|
-
visitReadKeyExpr(ast, context) {
|
|
200
|
-
return this.factory.createElementAccess(ast.receiver.visitExpression(this, context), ast.index.visitExpression(this, context));
|
|
201
|
-
}
|
|
202
|
-
visitLiteralArrayExpr(ast, context) {
|
|
203
|
-
return this.factory.createArrayLiteral(ast.entries.map((expr) => this.setSourceMapRange(expr.visitExpression(this, context), ast.sourceSpan)));
|
|
204
|
-
}
|
|
205
|
-
visitLiteralMapExpr(ast, context) {
|
|
206
|
-
const properties = ast.entries.map((entry) => {
|
|
207
|
-
return {
|
|
208
|
-
propertyName: entry.key,
|
|
209
|
-
quoted: entry.quoted,
|
|
210
|
-
value: entry.value.visitExpression(this, context)
|
|
211
|
-
};
|
|
212
|
-
});
|
|
213
|
-
return this.setSourceMapRange(this.factory.createObjectLiteral(properties), ast.sourceSpan);
|
|
214
|
-
}
|
|
215
|
-
visitCommaExpr(ast, context) {
|
|
216
|
-
throw new Error("Method not implemented.");
|
|
217
|
-
}
|
|
218
|
-
visitWrappedNodeExpr(ast, _context) {
|
|
219
|
-
this.recordWrappedNode(ast);
|
|
220
|
-
return ast.node;
|
|
221
|
-
}
|
|
222
|
-
visitTypeofExpr(ast, context) {
|
|
223
|
-
return this.factory.createTypeOfExpression(ast.expr.visitExpression(this, context));
|
|
224
|
-
}
|
|
225
|
-
visitUnaryOperatorExpr(ast, context) {
|
|
226
|
-
if (!UNARY_OPERATORS.has(ast.operator)) {
|
|
227
|
-
throw new Error(`Unknown unary operator: ${o.UnaryOperator[ast.operator]}`);
|
|
228
|
-
}
|
|
229
|
-
return this.factory.createUnaryExpression(UNARY_OPERATORS.get(ast.operator), ast.expr.visitExpression(this, context));
|
|
230
|
-
}
|
|
231
|
-
visitStatements(statements, context) {
|
|
232
|
-
return statements.map((stmt) => stmt.visitStatement(this, context)).filter((stmt) => stmt !== void 0);
|
|
233
|
-
}
|
|
234
|
-
setSourceMapRange(ast, span) {
|
|
235
|
-
return this.factory.setSourceMapRange(ast, createRange(span));
|
|
236
|
-
}
|
|
237
|
-
attachComments(statement, leadingComments) {
|
|
238
|
-
if (leadingComments !== void 0) {
|
|
239
|
-
this.factory.attachComments(statement, leadingComments);
|
|
240
|
-
}
|
|
241
|
-
return statement;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
function createTemplateElement({ cooked, raw, range }) {
|
|
245
|
-
return { cooked, raw, range: createRange(range) };
|
|
246
|
-
}
|
|
247
|
-
function createRange(span) {
|
|
248
|
-
if (span === null) {
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
const { start, end } = span;
|
|
252
|
-
const { url, content } = start.file;
|
|
253
|
-
if (!url) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
return {
|
|
257
|
-
url,
|
|
258
|
-
content,
|
|
259
|
-
start: { offset: start.offset, line: start.line, column: start.col },
|
|
260
|
-
end: { offset: end.offset, line: end.line, column: end.col }
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/import_manager.mjs
|
|
265
|
-
import ts from "typescript";
|
|
266
|
-
var ImportManager = class {
|
|
267
|
-
constructor(rewriter = new NoopImportRewriter(), prefix = "i") {
|
|
268
|
-
this.rewriter = rewriter;
|
|
269
|
-
this.prefix = prefix;
|
|
270
|
-
this.specifierToIdentifier = /* @__PURE__ */ new Map();
|
|
271
|
-
this.nextIndex = 0;
|
|
272
|
-
}
|
|
273
|
-
generateNamespaceImport(moduleName) {
|
|
274
|
-
if (!this.specifierToIdentifier.has(moduleName)) {
|
|
275
|
-
this.specifierToIdentifier.set(moduleName, ts.factory.createIdentifier(`${this.prefix}${this.nextIndex++}`));
|
|
276
|
-
}
|
|
277
|
-
return this.specifierToIdentifier.get(moduleName);
|
|
278
|
-
}
|
|
279
|
-
generateNamedImport(moduleName, originalSymbol) {
|
|
280
|
-
const symbol = this.rewriter.rewriteSymbol(originalSymbol, moduleName);
|
|
281
|
-
if (!this.rewriter.shouldImportSymbol(symbol, moduleName)) {
|
|
282
|
-
return { moduleImport: null, symbol };
|
|
283
|
-
}
|
|
284
|
-
const moduleImport = this.generateNamespaceImport(moduleName);
|
|
285
|
-
return { moduleImport, symbol };
|
|
286
|
-
}
|
|
287
|
-
getAllImports(contextPath) {
|
|
288
|
-
const imports = [];
|
|
289
|
-
for (const [originalSpecifier, qualifier] of this.specifierToIdentifier) {
|
|
290
|
-
const specifier = this.rewriter.rewriteSpecifier(originalSpecifier, contextPath);
|
|
291
|
-
imports.push({
|
|
292
|
-
specifier,
|
|
293
|
-
qualifier
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
return imports;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/type_emitter.mjs
|
|
301
|
-
import ts2 from "typescript";
|
|
302
|
-
var INELIGIBLE = {};
|
|
303
|
-
function canEmitType(type, canEmit) {
|
|
304
|
-
return canEmitTypeWorker(type);
|
|
305
|
-
function canEmitTypeWorker(type2) {
|
|
306
|
-
return visitNode(type2) !== INELIGIBLE;
|
|
307
|
-
}
|
|
308
|
-
function visitNode(node) {
|
|
309
|
-
if (ts2.isImportTypeNode(node)) {
|
|
310
|
-
return INELIGIBLE;
|
|
311
|
-
}
|
|
312
|
-
if (ts2.isTypeReferenceNode(node) && !canEmitTypeReference(node)) {
|
|
313
|
-
return INELIGIBLE;
|
|
314
|
-
} else {
|
|
315
|
-
return ts2.forEachChild(node, visitNode);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function canEmitTypeReference(type2) {
|
|
319
|
-
if (!canEmit(type2)) {
|
|
320
|
-
return false;
|
|
321
|
-
}
|
|
322
|
-
return type2.typeArguments === void 0 || type2.typeArguments.every(canEmitTypeWorker);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
var TypeEmitter = class {
|
|
326
|
-
constructor(translator) {
|
|
327
|
-
this.translator = translator;
|
|
328
|
-
}
|
|
329
|
-
emitType(type) {
|
|
330
|
-
const typeReferenceTransformer = (context) => {
|
|
331
|
-
const visitNode = (node) => {
|
|
332
|
-
if (ts2.isImportTypeNode(node)) {
|
|
333
|
-
throw new Error("Unable to emit import type");
|
|
334
|
-
}
|
|
335
|
-
if (ts2.isTypeReferenceNode(node)) {
|
|
336
|
-
return this.emitTypeReference(node);
|
|
337
|
-
} else if (ts2.isLiteralExpression(node)) {
|
|
338
|
-
let clone;
|
|
339
|
-
if (ts2.isStringLiteral(node)) {
|
|
340
|
-
clone = ts2.factory.createStringLiteral(node.text);
|
|
341
|
-
} else if (ts2.isNumericLiteral(node)) {
|
|
342
|
-
clone = ts2.factory.createNumericLiteral(node.text);
|
|
343
|
-
} else if (ts2.isBigIntLiteral(node)) {
|
|
344
|
-
clone = ts2.factory.createBigIntLiteral(node.text);
|
|
345
|
-
} else if (ts2.isNoSubstitutionTemplateLiteral(node)) {
|
|
346
|
-
clone = ts2.factory.createNoSubstitutionTemplateLiteral(node.text, node.rawText);
|
|
347
|
-
} else if (ts2.isRegularExpressionLiteral(node)) {
|
|
348
|
-
clone = ts2.factory.createRegularExpressionLiteral(node.text);
|
|
349
|
-
} else {
|
|
350
|
-
throw new Error(`Unsupported literal kind ${ts2.SyntaxKind[node.kind]}`);
|
|
351
|
-
}
|
|
352
|
-
ts2.setTextRange(clone, { pos: -1, end: -1 });
|
|
353
|
-
return clone;
|
|
354
|
-
} else {
|
|
355
|
-
return ts2.visitEachChild(node, visitNode, context);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
return (node) => ts2.visitNode(node, visitNode, ts2.isTypeNode);
|
|
359
|
-
};
|
|
360
|
-
return ts2.transform(type, [typeReferenceTransformer]).transformed[0];
|
|
361
|
-
}
|
|
362
|
-
emitTypeReference(type) {
|
|
363
|
-
const translatedType = this.translator(type);
|
|
364
|
-
if (translatedType === null) {
|
|
365
|
-
throw new Error("Unable to emit an unresolved reference");
|
|
366
|
-
}
|
|
367
|
-
let typeArguments = void 0;
|
|
368
|
-
if (type.typeArguments !== void 0) {
|
|
369
|
-
typeArguments = ts2.factory.createNodeArray(type.typeArguments.map((typeArg) => this.emitType(typeArg)));
|
|
370
|
-
}
|
|
371
|
-
return ts2.factory.updateTypeReferenceNode(type, translatedType.typeName, typeArguments);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/type_translator.mjs
|
|
376
|
-
import * as o2 from "@angular/compiler";
|
|
377
|
-
import ts4 from "typescript";
|
|
378
|
-
|
|
379
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/ts_util.mjs
|
|
380
|
-
import ts3 from "typescript";
|
|
381
|
-
function tsNumericExpression(value) {
|
|
382
|
-
if (value < 0) {
|
|
383
|
-
const operand = ts3.factory.createNumericLiteral(Math.abs(value));
|
|
384
|
-
return ts3.factory.createPrefixUnaryExpression(ts3.SyntaxKind.MinusToken, operand);
|
|
385
|
-
}
|
|
386
|
-
return ts3.factory.createNumericLiteral(value);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/type_translator.mjs
|
|
390
|
-
function translateType(type, contextFile, reflector, refEmitter, imports) {
|
|
391
|
-
return type.visitType(new TypeTranslatorVisitor(imports, contextFile, reflector, refEmitter), new Context(false));
|
|
392
|
-
}
|
|
393
|
-
var TypeTranslatorVisitor = class {
|
|
394
|
-
constructor(imports, contextFile, reflector, refEmitter) {
|
|
395
|
-
this.imports = imports;
|
|
396
|
-
this.contextFile = contextFile;
|
|
397
|
-
this.reflector = reflector;
|
|
398
|
-
this.refEmitter = refEmitter;
|
|
399
|
-
}
|
|
400
|
-
visitBuiltinType(type, context) {
|
|
401
|
-
switch (type.name) {
|
|
402
|
-
case o2.BuiltinTypeName.Bool:
|
|
403
|
-
return ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.BooleanKeyword);
|
|
404
|
-
case o2.BuiltinTypeName.Dynamic:
|
|
405
|
-
return ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.AnyKeyword);
|
|
406
|
-
case o2.BuiltinTypeName.Int:
|
|
407
|
-
case o2.BuiltinTypeName.Number:
|
|
408
|
-
return ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.NumberKeyword);
|
|
409
|
-
case o2.BuiltinTypeName.String:
|
|
410
|
-
return ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.StringKeyword);
|
|
411
|
-
case o2.BuiltinTypeName.None:
|
|
412
|
-
return ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.NeverKeyword);
|
|
413
|
-
default:
|
|
414
|
-
throw new Error(`Unsupported builtin type: ${o2.BuiltinTypeName[type.name]}`);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
visitExpressionType(type, context) {
|
|
418
|
-
const typeNode = this.translateExpression(type.value, context);
|
|
419
|
-
if (type.typeParams === null) {
|
|
420
|
-
return typeNode;
|
|
421
|
-
}
|
|
422
|
-
if (!ts4.isTypeReferenceNode(typeNode)) {
|
|
423
|
-
throw new Error("An ExpressionType with type arguments must translate into a TypeReferenceNode");
|
|
424
|
-
} else if (typeNode.typeArguments !== void 0) {
|
|
425
|
-
throw new Error(`An ExpressionType with type arguments cannot have multiple levels of type arguments`);
|
|
426
|
-
}
|
|
427
|
-
const typeArgs = type.typeParams.map((param) => this.translateType(param, context));
|
|
428
|
-
return ts4.factory.createTypeReferenceNode(typeNode.typeName, typeArgs);
|
|
429
|
-
}
|
|
430
|
-
visitArrayType(type, context) {
|
|
431
|
-
return ts4.factory.createArrayTypeNode(this.translateType(type.of, context));
|
|
432
|
-
}
|
|
433
|
-
visitMapType(type, context) {
|
|
434
|
-
const parameter = ts4.factory.createParameterDeclaration(void 0, void 0, "key", void 0, ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.StringKeyword));
|
|
435
|
-
const typeArgs = type.valueType !== null ? this.translateType(type.valueType, context) : ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.UnknownKeyword);
|
|
436
|
-
const indexSignature = ts4.factory.createIndexSignature(void 0, [parameter], typeArgs);
|
|
437
|
-
return ts4.factory.createTypeLiteralNode([indexSignature]);
|
|
438
|
-
}
|
|
439
|
-
visitTransplantedType(ast, context) {
|
|
440
|
-
const node = ast.type instanceof Reference ? ast.type.node : ast.type;
|
|
441
|
-
if (!ts4.isTypeNode(node)) {
|
|
442
|
-
throw new Error(`A TransplantedType must wrap a TypeNode`);
|
|
443
|
-
}
|
|
444
|
-
const viaModule = ast.type instanceof Reference ? ast.type.bestGuessOwningModule : null;
|
|
445
|
-
const emitter = new TypeEmitter((typeRef) => this.translateTypeReference(typeRef, context, viaModule));
|
|
446
|
-
return emitter.emitType(node);
|
|
447
|
-
}
|
|
448
|
-
visitReadVarExpr(ast, context) {
|
|
449
|
-
if (ast.name === null) {
|
|
450
|
-
throw new Error(`ReadVarExpr with no variable name in type`);
|
|
451
|
-
}
|
|
452
|
-
return ts4.factory.createTypeQueryNode(ts4.factory.createIdentifier(ast.name));
|
|
453
|
-
}
|
|
454
|
-
visitWriteVarExpr(expr, context) {
|
|
455
|
-
throw new Error("Method not implemented.");
|
|
456
|
-
}
|
|
457
|
-
visitWriteKeyExpr(expr, context) {
|
|
458
|
-
throw new Error("Method not implemented.");
|
|
459
|
-
}
|
|
460
|
-
visitWritePropExpr(expr, context) {
|
|
461
|
-
throw new Error("Method not implemented.");
|
|
462
|
-
}
|
|
463
|
-
visitInvokeFunctionExpr(ast, context) {
|
|
464
|
-
throw new Error("Method not implemented.");
|
|
465
|
-
}
|
|
466
|
-
visitTaggedTemplateExpr(ast, context) {
|
|
467
|
-
throw new Error("Method not implemented.");
|
|
468
|
-
}
|
|
469
|
-
visitInstantiateExpr(ast, context) {
|
|
470
|
-
throw new Error("Method not implemented.");
|
|
471
|
-
}
|
|
472
|
-
visitLiteralExpr(ast, context) {
|
|
473
|
-
if (ast.value === null) {
|
|
474
|
-
return ts4.factory.createLiteralTypeNode(ts4.factory.createNull());
|
|
475
|
-
} else if (ast.value === void 0) {
|
|
476
|
-
return ts4.factory.createKeywordTypeNode(ts4.SyntaxKind.UndefinedKeyword);
|
|
477
|
-
} else if (typeof ast.value === "boolean") {
|
|
478
|
-
return ts4.factory.createLiteralTypeNode(ast.value ? ts4.factory.createTrue() : ts4.factory.createFalse());
|
|
479
|
-
} else if (typeof ast.value === "number") {
|
|
480
|
-
return ts4.factory.createLiteralTypeNode(tsNumericExpression(ast.value));
|
|
481
|
-
} else {
|
|
482
|
-
return ts4.factory.createLiteralTypeNode(ts4.factory.createStringLiteral(ast.value));
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
visitLocalizedString(ast, context) {
|
|
486
|
-
throw new Error("Method not implemented.");
|
|
487
|
-
}
|
|
488
|
-
visitExternalExpr(ast, context) {
|
|
489
|
-
if (ast.value.moduleName === null || ast.value.name === null) {
|
|
490
|
-
throw new Error(`Import unknown module or symbol`);
|
|
491
|
-
}
|
|
492
|
-
const { moduleImport, symbol } = this.imports.generateNamedImport(ast.value.moduleName, ast.value.name);
|
|
493
|
-
const symbolIdentifier = ts4.factory.createIdentifier(symbol);
|
|
494
|
-
const typeName = moduleImport ? ts4.factory.createQualifiedName(moduleImport, symbolIdentifier) : symbolIdentifier;
|
|
495
|
-
const typeArguments = ast.typeParams !== null ? ast.typeParams.map((type) => this.translateType(type, context)) : void 0;
|
|
496
|
-
return ts4.factory.createTypeReferenceNode(typeName, typeArguments);
|
|
497
|
-
}
|
|
498
|
-
visitConditionalExpr(ast, context) {
|
|
499
|
-
throw new Error("Method not implemented.");
|
|
500
|
-
}
|
|
501
|
-
visitDynamicImportExpr(ast, context) {
|
|
502
|
-
throw new Error("Method not implemented.");
|
|
503
|
-
}
|
|
504
|
-
visitNotExpr(ast, context) {
|
|
505
|
-
throw new Error("Method not implemented.");
|
|
506
|
-
}
|
|
507
|
-
visitFunctionExpr(ast, context) {
|
|
508
|
-
throw new Error("Method not implemented.");
|
|
509
|
-
}
|
|
510
|
-
visitArrowFunctionExpr(ast, context) {
|
|
511
|
-
throw new Error("Method not implemented.");
|
|
512
|
-
}
|
|
513
|
-
visitUnaryOperatorExpr(ast, context) {
|
|
514
|
-
throw new Error("Method not implemented.");
|
|
515
|
-
}
|
|
516
|
-
visitBinaryOperatorExpr(ast, context) {
|
|
517
|
-
throw new Error("Method not implemented.");
|
|
518
|
-
}
|
|
519
|
-
visitReadPropExpr(ast, context) {
|
|
520
|
-
throw new Error("Method not implemented.");
|
|
521
|
-
}
|
|
522
|
-
visitReadKeyExpr(ast, context) {
|
|
523
|
-
throw new Error("Method not implemented.");
|
|
524
|
-
}
|
|
525
|
-
visitLiteralArrayExpr(ast, context) {
|
|
526
|
-
const values = ast.entries.map((expr) => this.translateExpression(expr, context));
|
|
527
|
-
return ts4.factory.createTupleTypeNode(values);
|
|
528
|
-
}
|
|
529
|
-
visitLiteralMapExpr(ast, context) {
|
|
530
|
-
const entries = ast.entries.map((entry) => {
|
|
531
|
-
const { key, quoted } = entry;
|
|
532
|
-
const type = this.translateExpression(entry.value, context);
|
|
533
|
-
return ts4.factory.createPropertySignature(
|
|
534
|
-
void 0,
|
|
535
|
-
quoted ? ts4.factory.createStringLiteral(key) : key,
|
|
536
|
-
void 0,
|
|
537
|
-
type
|
|
538
|
-
);
|
|
539
|
-
});
|
|
540
|
-
return ts4.factory.createTypeLiteralNode(entries);
|
|
541
|
-
}
|
|
542
|
-
visitCommaExpr(ast, context) {
|
|
543
|
-
throw new Error("Method not implemented.");
|
|
544
|
-
}
|
|
545
|
-
visitWrappedNodeExpr(ast, context) {
|
|
546
|
-
const node = ast.node;
|
|
547
|
-
if (ts4.isEntityName(node)) {
|
|
548
|
-
return ts4.factory.createTypeReferenceNode(node, void 0);
|
|
549
|
-
} else if (ts4.isTypeNode(node)) {
|
|
550
|
-
return node;
|
|
551
|
-
} else if (ts4.isLiteralExpression(node)) {
|
|
552
|
-
return ts4.factory.createLiteralTypeNode(node);
|
|
553
|
-
} else {
|
|
554
|
-
throw new Error(`Unsupported WrappedNodeExpr in TypeTranslatorVisitor: ${ts4.SyntaxKind[node.kind]}`);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
visitTypeofExpr(ast, context) {
|
|
558
|
-
const typeNode = this.translateExpression(ast.expr, context);
|
|
559
|
-
if (!ts4.isTypeReferenceNode(typeNode)) {
|
|
560
|
-
throw new Error(`The target of a typeof expression must be a type reference, but it was
|
|
561
|
-
${ts4.SyntaxKind[typeNode.kind]}`);
|
|
562
|
-
}
|
|
563
|
-
return ts4.factory.createTypeQueryNode(typeNode.typeName);
|
|
564
|
-
}
|
|
565
|
-
translateType(type, context) {
|
|
566
|
-
const typeNode = type.visitType(this, context);
|
|
567
|
-
if (!ts4.isTypeNode(typeNode)) {
|
|
568
|
-
throw new Error(`A Type must translate to a TypeNode, but was ${ts4.SyntaxKind[typeNode.kind]}`);
|
|
569
|
-
}
|
|
570
|
-
return typeNode;
|
|
571
|
-
}
|
|
572
|
-
translateExpression(expr, context) {
|
|
573
|
-
const typeNode = expr.visitExpression(this, context);
|
|
574
|
-
if (!ts4.isTypeNode(typeNode)) {
|
|
575
|
-
throw new Error(`An Expression must translate to a TypeNode, but was ${ts4.SyntaxKind[typeNode.kind]}`);
|
|
576
|
-
}
|
|
577
|
-
return typeNode;
|
|
578
|
-
}
|
|
579
|
-
translateTypeReference(type, context, viaModule) {
|
|
580
|
-
const target = ts4.isIdentifier(type.typeName) ? type.typeName : type.typeName.right;
|
|
581
|
-
const declaration = this.reflector.getDeclarationOfIdentifier(target);
|
|
582
|
-
if (declaration === null) {
|
|
583
|
-
throw new Error(`Unable to statically determine the declaration file of type node ${target.text}`);
|
|
584
|
-
}
|
|
585
|
-
let owningModule = viaModule;
|
|
586
|
-
if (typeof declaration.viaModule === "string") {
|
|
587
|
-
owningModule = {
|
|
588
|
-
specifier: declaration.viaModule,
|
|
589
|
-
resolutionContext: type.getSourceFile().fileName
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
const reference = new Reference(declaration.node, declaration.viaModule === AmbientImport ? AmbientImport : owningModule);
|
|
593
|
-
const emittedType = this.refEmitter.emit(reference, this.contextFile, ImportFlags.NoAliasing | ImportFlags.AllowTypeImports | ImportFlags.AllowAmbientReferences);
|
|
594
|
-
assertSuccessfulReferenceEmit(emittedType, target, "type");
|
|
595
|
-
const typeNode = this.translateExpression(emittedType.expression, context);
|
|
596
|
-
if (!ts4.isTypeReferenceNode(typeNode)) {
|
|
597
|
-
throw new Error(`Expected TypeReferenceNode for emitted reference, got ${ts4.SyntaxKind[typeNode.kind]}.`);
|
|
598
|
-
}
|
|
599
|
-
return typeNode;
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.mjs
|
|
604
|
-
import ts5 from "typescript";
|
|
605
|
-
var PureAnnotation;
|
|
606
|
-
(function(PureAnnotation2) {
|
|
607
|
-
PureAnnotation2["CLOSURE"] = "* @pureOrBreakMyCode ";
|
|
608
|
-
PureAnnotation2["TERSER"] = "@__PURE__";
|
|
609
|
-
})(PureAnnotation || (PureAnnotation = {}));
|
|
610
|
-
var UNARY_OPERATORS2 = {
|
|
611
|
-
"+": ts5.SyntaxKind.PlusToken,
|
|
612
|
-
"-": ts5.SyntaxKind.MinusToken,
|
|
613
|
-
"!": ts5.SyntaxKind.ExclamationToken
|
|
614
|
-
};
|
|
615
|
-
var BINARY_OPERATORS2 = {
|
|
616
|
-
"&&": ts5.SyntaxKind.AmpersandAmpersandToken,
|
|
617
|
-
">": ts5.SyntaxKind.GreaterThanToken,
|
|
618
|
-
">=": ts5.SyntaxKind.GreaterThanEqualsToken,
|
|
619
|
-
"&": ts5.SyntaxKind.AmpersandToken,
|
|
620
|
-
"/": ts5.SyntaxKind.SlashToken,
|
|
621
|
-
"==": ts5.SyntaxKind.EqualsEqualsToken,
|
|
622
|
-
"===": ts5.SyntaxKind.EqualsEqualsEqualsToken,
|
|
623
|
-
"<": ts5.SyntaxKind.LessThanToken,
|
|
624
|
-
"<=": ts5.SyntaxKind.LessThanEqualsToken,
|
|
625
|
-
"-": ts5.SyntaxKind.MinusToken,
|
|
626
|
-
"%": ts5.SyntaxKind.PercentToken,
|
|
627
|
-
"*": ts5.SyntaxKind.AsteriskToken,
|
|
628
|
-
"!=": ts5.SyntaxKind.ExclamationEqualsToken,
|
|
629
|
-
"!==": ts5.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
630
|
-
"||": ts5.SyntaxKind.BarBarToken,
|
|
631
|
-
"+": ts5.SyntaxKind.PlusToken,
|
|
632
|
-
"??": ts5.SyntaxKind.QuestionQuestionToken
|
|
633
|
-
};
|
|
634
|
-
var VAR_TYPES = {
|
|
635
|
-
"const": ts5.NodeFlags.Const,
|
|
636
|
-
"let": ts5.NodeFlags.Let,
|
|
637
|
-
"var": ts5.NodeFlags.None
|
|
638
|
-
};
|
|
639
|
-
var TypeScriptAstFactory = class {
|
|
640
|
-
constructor(annotateForClosureCompiler) {
|
|
641
|
-
this.annotateForClosureCompiler = annotateForClosureCompiler;
|
|
642
|
-
this.externalSourceFiles = /* @__PURE__ */ new Map();
|
|
643
|
-
this.attachComments = attachComments;
|
|
644
|
-
this.createArrayLiteral = ts5.factory.createArrayLiteralExpression;
|
|
645
|
-
this.createElementAccess = ts5.factory.createElementAccessExpression;
|
|
646
|
-
this.createExpressionStatement = ts5.factory.createExpressionStatement;
|
|
647
|
-
this.createIdentifier = ts5.factory.createIdentifier;
|
|
648
|
-
this.createParenthesizedExpression = ts5.factory.createParenthesizedExpression;
|
|
649
|
-
this.createPropertyAccess = ts5.factory.createPropertyAccessExpression;
|
|
650
|
-
this.createThrowStatement = ts5.factory.createThrowStatement;
|
|
651
|
-
this.createTypeOfExpression = ts5.factory.createTypeOfExpression;
|
|
652
|
-
}
|
|
653
|
-
createAssignment(target, value) {
|
|
654
|
-
return ts5.factory.createBinaryExpression(target, ts5.SyntaxKind.EqualsToken, value);
|
|
655
|
-
}
|
|
656
|
-
createBinaryExpression(leftOperand, operator, rightOperand) {
|
|
657
|
-
return ts5.factory.createBinaryExpression(leftOperand, BINARY_OPERATORS2[operator], rightOperand);
|
|
658
|
-
}
|
|
659
|
-
createBlock(body) {
|
|
660
|
-
return ts5.factory.createBlock(body);
|
|
661
|
-
}
|
|
662
|
-
createCallExpression(callee, args, pure) {
|
|
663
|
-
const call = ts5.factory.createCallExpression(callee, void 0, args);
|
|
664
|
-
if (pure) {
|
|
665
|
-
ts5.addSyntheticLeadingComment(
|
|
666
|
-
call,
|
|
667
|
-
ts5.SyntaxKind.MultiLineCommentTrivia,
|
|
668
|
-
this.annotateForClosureCompiler ? PureAnnotation.CLOSURE : PureAnnotation.TERSER,
|
|
669
|
-
false
|
|
670
|
-
);
|
|
671
|
-
}
|
|
672
|
-
return call;
|
|
673
|
-
}
|
|
674
|
-
createConditional(condition, whenTrue, whenFalse) {
|
|
675
|
-
return ts5.factory.createConditionalExpression(condition, void 0, whenTrue, void 0, whenFalse);
|
|
676
|
-
}
|
|
677
|
-
createDynamicImport(url) {
|
|
678
|
-
return ts5.factory.createCallExpression(
|
|
679
|
-
ts5.factory.createToken(ts5.SyntaxKind.ImportKeyword),
|
|
680
|
-
void 0,
|
|
681
|
-
[ts5.factory.createStringLiteral(url)]
|
|
682
|
-
);
|
|
683
|
-
}
|
|
684
|
-
createFunctionDeclaration(functionName, parameters, body) {
|
|
685
|
-
if (!ts5.isBlock(body)) {
|
|
686
|
-
throw new Error(`Invalid syntax, expected a block, but got ${ts5.SyntaxKind[body.kind]}.`);
|
|
687
|
-
}
|
|
688
|
-
return ts5.factory.createFunctionDeclaration(void 0, void 0, functionName, void 0, parameters.map((param) => ts5.factory.createParameterDeclaration(void 0, void 0, param)), void 0, body);
|
|
689
|
-
}
|
|
690
|
-
createFunctionExpression(functionName, parameters, body) {
|
|
691
|
-
if (!ts5.isBlock(body)) {
|
|
692
|
-
throw new Error(`Invalid syntax, expected a block, but got ${ts5.SyntaxKind[body.kind]}.`);
|
|
693
|
-
}
|
|
694
|
-
return ts5.factory.createFunctionExpression(void 0, void 0, functionName != null ? functionName : void 0, void 0, parameters.map((param) => ts5.factory.createParameterDeclaration(void 0, void 0, param)), void 0, body);
|
|
695
|
-
}
|
|
696
|
-
createArrowFunctionExpression(parameters, body) {
|
|
697
|
-
if (ts5.isStatement(body) && !ts5.isBlock(body)) {
|
|
698
|
-
throw new Error(`Invalid syntax, expected a block, but got ${ts5.SyntaxKind[body.kind]}.`);
|
|
699
|
-
}
|
|
700
|
-
return ts5.factory.createArrowFunction(void 0, void 0, parameters.map((param) => ts5.factory.createParameterDeclaration(void 0, void 0, param)), void 0, void 0, body);
|
|
701
|
-
}
|
|
702
|
-
createIfStatement(condition, thenStatement, elseStatement) {
|
|
703
|
-
return ts5.factory.createIfStatement(condition, thenStatement, elseStatement != null ? elseStatement : void 0);
|
|
704
|
-
}
|
|
705
|
-
createLiteral(value) {
|
|
706
|
-
if (value === void 0) {
|
|
707
|
-
return ts5.factory.createIdentifier("undefined");
|
|
708
|
-
} else if (value === null) {
|
|
709
|
-
return ts5.factory.createNull();
|
|
710
|
-
} else if (typeof value === "boolean") {
|
|
711
|
-
return value ? ts5.factory.createTrue() : ts5.factory.createFalse();
|
|
712
|
-
} else if (typeof value === "number") {
|
|
713
|
-
return tsNumericExpression(value);
|
|
714
|
-
} else {
|
|
715
|
-
return ts5.factory.createStringLiteral(value);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
createNewExpression(expression, args) {
|
|
719
|
-
return ts5.factory.createNewExpression(expression, void 0, args);
|
|
720
|
-
}
|
|
721
|
-
createObjectLiteral(properties) {
|
|
722
|
-
return ts5.factory.createObjectLiteralExpression(properties.map((prop) => ts5.factory.createPropertyAssignment(prop.quoted ? ts5.factory.createStringLiteral(prop.propertyName) : ts5.factory.createIdentifier(prop.propertyName), prop.value)));
|
|
723
|
-
}
|
|
724
|
-
createReturnStatement(expression) {
|
|
725
|
-
return ts5.factory.createReturnStatement(expression != null ? expression : void 0);
|
|
726
|
-
}
|
|
727
|
-
createTaggedTemplate(tag, template) {
|
|
728
|
-
let templateLiteral;
|
|
729
|
-
const length = template.elements.length;
|
|
730
|
-
const head = template.elements[0];
|
|
731
|
-
if (length === 1) {
|
|
732
|
-
templateLiteral = ts5.factory.createNoSubstitutionTemplateLiteral(head.cooked, head.raw);
|
|
733
|
-
} else {
|
|
734
|
-
const spans = [];
|
|
735
|
-
for (let i = 1; i < length - 1; i++) {
|
|
736
|
-
const { cooked, raw, range } = template.elements[i];
|
|
737
|
-
const middle = createTemplateMiddle(cooked, raw);
|
|
738
|
-
if (range !== null) {
|
|
739
|
-
this.setSourceMapRange(middle, range);
|
|
740
|
-
}
|
|
741
|
-
spans.push(ts5.factory.createTemplateSpan(template.expressions[i - 1], middle));
|
|
742
|
-
}
|
|
743
|
-
const resolvedExpression = template.expressions[length - 2];
|
|
744
|
-
const templatePart = template.elements[length - 1];
|
|
745
|
-
const templateTail = createTemplateTail(templatePart.cooked, templatePart.raw);
|
|
746
|
-
if (templatePart.range !== null) {
|
|
747
|
-
this.setSourceMapRange(templateTail, templatePart.range);
|
|
748
|
-
}
|
|
749
|
-
spans.push(ts5.factory.createTemplateSpan(resolvedExpression, templateTail));
|
|
750
|
-
templateLiteral = ts5.factory.createTemplateExpression(ts5.factory.createTemplateHead(head.cooked, head.raw), spans);
|
|
751
|
-
}
|
|
752
|
-
if (head.range !== null) {
|
|
753
|
-
this.setSourceMapRange(templateLiteral, head.range);
|
|
754
|
-
}
|
|
755
|
-
return ts5.factory.createTaggedTemplateExpression(tag, void 0, templateLiteral);
|
|
756
|
-
}
|
|
757
|
-
createUnaryExpression(operator, operand) {
|
|
758
|
-
return ts5.factory.createPrefixUnaryExpression(UNARY_OPERATORS2[operator], operand);
|
|
759
|
-
}
|
|
760
|
-
createVariableDeclaration(variableName, initializer, type) {
|
|
761
|
-
return ts5.factory.createVariableStatement(void 0, ts5.factory.createVariableDeclarationList([ts5.factory.createVariableDeclaration(variableName, void 0, void 0, initializer != null ? initializer : void 0)], VAR_TYPES[type]));
|
|
762
|
-
}
|
|
763
|
-
setSourceMapRange(node, sourceMapRange) {
|
|
764
|
-
if (sourceMapRange === null) {
|
|
765
|
-
return node;
|
|
766
|
-
}
|
|
767
|
-
const url = sourceMapRange.url;
|
|
768
|
-
if (!this.externalSourceFiles.has(url)) {
|
|
769
|
-
this.externalSourceFiles.set(url, ts5.createSourceMapSource(url, sourceMapRange.content, (pos) => pos));
|
|
770
|
-
}
|
|
771
|
-
const source = this.externalSourceFiles.get(url);
|
|
772
|
-
ts5.setSourceMapRange(node, { pos: sourceMapRange.start.offset, end: sourceMapRange.end.offset, source });
|
|
773
|
-
return node;
|
|
774
|
-
}
|
|
775
|
-
};
|
|
776
|
-
function createTemplateMiddle(cooked, raw) {
|
|
777
|
-
const node = ts5.factory.createTemplateHead(cooked, raw);
|
|
778
|
-
node.kind = ts5.SyntaxKind.TemplateMiddle;
|
|
779
|
-
return node;
|
|
780
|
-
}
|
|
781
|
-
function createTemplateTail(cooked, raw) {
|
|
782
|
-
const node = ts5.factory.createTemplateHead(cooked, raw);
|
|
783
|
-
node.kind = ts5.SyntaxKind.TemplateTail;
|
|
784
|
-
return node;
|
|
785
|
-
}
|
|
786
|
-
function attachComments(statement, leadingComments) {
|
|
787
|
-
for (const comment of leadingComments) {
|
|
788
|
-
const commentKind = comment.multiline ? ts5.SyntaxKind.MultiLineCommentTrivia : ts5.SyntaxKind.SingleLineCommentTrivia;
|
|
789
|
-
if (comment.multiline) {
|
|
790
|
-
ts5.addSyntheticLeadingComment(statement, commentKind, comment.toString(), comment.trailingNewline);
|
|
791
|
-
} else {
|
|
792
|
-
for (const line of comment.toString().split("\n")) {
|
|
793
|
-
ts5.addSyntheticLeadingComment(statement, commentKind, line, comment.trailingNewline);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// bazel-out/darwin_arm64-fastbuild/bin/packages/compiler-cli/src/ngtsc/translator/src/typescript_translator.mjs
|
|
800
|
-
function translateExpression(expression, imports, options = {}) {
|
|
801
|
-
return expression.visitExpression(new ExpressionTranslatorVisitor(new TypeScriptAstFactory(options.annotateForClosureCompiler === true), imports, options), new Context(false));
|
|
802
|
-
}
|
|
803
|
-
function translateStatement(statement, imports, options = {}) {
|
|
804
|
-
return statement.visitStatement(new ExpressionTranslatorVisitor(new TypeScriptAstFactory(options.annotateForClosureCompiler === true), imports, options), new Context(true));
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
export {
|
|
808
|
-
Context,
|
|
809
|
-
ImportManager,
|
|
810
|
-
ExpressionTranslatorVisitor,
|
|
811
|
-
canEmitType,
|
|
812
|
-
TypeEmitter,
|
|
813
|
-
translateType,
|
|
814
|
-
translateExpression,
|
|
815
|
-
translateStatement
|
|
816
|
-
};
|
|
817
|
-
/*!
|
|
818
|
-
* @license
|
|
819
|
-
* Copyright Google LLC All Rights Reserved.
|
|
820
|
-
*
|
|
821
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
822
|
-
* found in the LICENSE file at https://angular.io/license
|
|
823
|
-
*/
|
|
824
|
-
/**
|
|
825
|
-
* @license
|
|
826
|
-
* Copyright Google LLC All Rights Reserved.
|
|
827
|
-
*
|
|
828
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
829
|
-
* found in the LICENSE file at https://angular.io/license
|
|
830
|
-
*/
|
|
831
|
-
//# sourceMappingURL=chunk-MFE4YVWE.js.map
|