static-injector 2.0.0 → 2.1.1
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/import/commonjs/index.js +425 -163
- package/import/es2015/di/create_injector.js +5 -1
- package/import/es2015/di/forward_ref.js +3 -3
- package/import/es2015/di/injection_token.js +18 -11
- package/import/es2015/di/injector_compatibility.js +19 -10
- package/import/es2015/di/injector_token.js +3 -3
- package/import/es2015/di/interface/defs.js +21 -12
- package/import/es2015/di/interface/provider.js +3 -1
- package/import/es2015/di/null_injector.js +3 -3
- package/import/es2015/di/provider_collection.js +196 -1
- package/import/es2015/di/r3_injector.js +31 -28
- package/import/es2015/error_details_base_url.js +19 -0
- package/import/es2015/errors.js +42 -0
- package/import/es2015/interface/type.js +14 -1
- package/import/es2015/render3/definition_factory.js +2 -3
- package/import/es2015/render3/errors_di.js +2 -3
- package/import/es2015/render3/instructions/di.js +0 -7
- package/import/es2015/render3/util/stringify_utils.js +5 -5
- package/import/es2015/util/array_utils.js +0 -7
- package/import/es2015/util/decorators.js +24 -1
- package/import/es2015/util/empty.js +4 -0
- package/import/es2015/util/stringify.js +5 -5
- package/import/fesm2015/index.js +422 -161
- package/import/typings/di/forward_ref.d.ts +1 -1
- package/import/typings/di/injectable.d.ts +5 -4
- package/import/typings/di/injection_token.d.ts +21 -6
- package/import/typings/di/injector.d.ts +16 -0
- package/import/typings/di/injector_compatibility.d.ts +11 -5
- package/import/typings/di/injector_token.d.ts +2 -2
- package/import/typings/di/interface/defs.d.ts +15 -8
- package/import/typings/di/interface/provider.d.ts +62 -2
- package/import/typings/di/null_injector.d.ts +1 -1
- package/import/typings/di/provider_collection.d.ts +55 -2
- package/import/typings/di/provider_token.d.ts +3 -3
- package/import/typings/di/r3_injector.d.ts +3 -8
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/error_details_base_url.d.ts +19 -0
- package/import/typings/errors.d.ts +89 -0
- package/import/typings/interface/type.d.ts +45 -0
- package/import/typings/render3/definition_factory.d.ts +1 -1
- package/import/typings/render3/errors_di.d.ts +7 -0
- package/import/typings/render3/instructions/di.d.ts +0 -7
- package/import/typings/util/array_utils.d.ts +15 -7
- package/import/typings/util/decorators.d.ts +2 -1
- package/import/typings/util/empty.d.ts +1 -0
- package/package.json +3 -3
- package/transform/compiler/compiler.d.ts +8 -0
- package/transform/compiler/compiler.js +28 -0
- package/transform/compiler/index.d.ts +8 -5
- package/transform/compiler/index.js +12 -5
- package/transform/compiler/public_api.d.ts +13 -0
- package/transform/compiler/public_api.js +30 -0
- package/transform/compiler/src/compiler.d.ts +27 -0
- package/transform/compiler/src/compiler.js +47 -0
- package/transform/compiler/src/output/output_ast.d.ts +1 -1
- package/transform/compiler/src/render3/partial/api.d.ts +1 -1
- package/transform/compiler/src/render3/partial/api.js +7 -0
- package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
- package/transform/compiler/src/render3/r3_factory.js +37 -56
- package/transform/compiler/src/render3/view/util.d.ts +0 -8
- package/transform/compiler/src/render3/view/util.js +0 -8
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +2 -2
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +3 -34
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +18 -216
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +31 -50
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +12 -13
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +7 -28
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +17 -41
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +46 -65
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -27
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +15 -35
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -24
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +76 -95
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +20 -126
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +23 -147
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -31
- package/transform/injectable-transform.js +36 -7
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import * as o from '
|
|
8
|
+
import * as o from 'static-injector/transform/compiler';
|
|
9
9
|
import { AstFactory } from './api/ast_factory';
|
|
10
10
|
import { ImportGenerator } from './api/import_generator';
|
|
11
11
|
import { Context } from './context';
|
|
12
|
-
export
|
|
12
|
+
export type RecordWrappedNodeFn<TExpression> = (node: o.WrappedNodeExpr<TExpression>) => void;
|
|
13
13
|
export interface TranslatorOptions<TExpression> {
|
|
14
14
|
downlevelTaggedTemplates?: boolean;
|
|
15
15
|
downlevelVariableDeclarations?: boolean;
|
|
@@ -31,7 +31,7 @@ exports.ExpressionTranslatorVisitor = void 0;
|
|
|
31
31
|
* Use of this source code is governed by an MIT-style license that can be
|
|
32
32
|
* found in the LICENSE file at https://angular.io/license
|
|
33
33
|
*/
|
|
34
|
-
const o = __importStar(require("
|
|
34
|
+
const o = __importStar(require("static-injector/transform/compiler"));
|
|
35
35
|
const UNARY_OPERATORS = new Map([
|
|
36
36
|
[o.UnaryOperator.Minus, '-'],
|
|
37
37
|
[o.UnaryOperator.Plus, '+'],
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import ts from 'typescript';
|
|
9
9
|
import { AstFactory, BinaryOperator, LeadingComment, ObjectLiteralProperty, SourceMapRange, TemplateLiteral, UnaryOperator, VariableDeclarationType } from './api/ast_factory';
|
|
10
10
|
/**
|
|
11
11
|
* A TypeScript flavoured implementation of the AstFactory.
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.attachComments = exports.createTemplateTail = exports.createTemplateMiddle = exports.TypeScriptAstFactory = void 0;
|
|
@@ -31,7 +11,8 @@ exports.attachComments = exports.createTemplateTail = exports.createTemplateMidd
|
|
|
31
11
|
* Use of this source code is governed by an MIT-style license that can be
|
|
32
12
|
* found in the LICENSE file at https://angular.io/license
|
|
33
13
|
*/
|
|
34
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
const ts_compatibility_1 = require("../../ts_compatibility");
|
|
35
16
|
/**
|
|
36
17
|
* Different optimizers use different annotations on a function or method call to indicate its pure
|
|
37
18
|
* status.
|
|
@@ -47,33 +28,33 @@ var PureAnnotation;
|
|
|
47
28
|
PureAnnotation["TERSER"] = "@__PURE__";
|
|
48
29
|
})(PureAnnotation || (PureAnnotation = {}));
|
|
49
30
|
const UNARY_OPERATORS = {
|
|
50
|
-
'+':
|
|
51
|
-
'-':
|
|
52
|
-
'!':
|
|
31
|
+
'+': typescript_1.default.SyntaxKind.PlusToken,
|
|
32
|
+
'-': typescript_1.default.SyntaxKind.MinusToken,
|
|
33
|
+
'!': typescript_1.default.SyntaxKind.ExclamationToken,
|
|
53
34
|
};
|
|
54
35
|
const BINARY_OPERATORS = {
|
|
55
|
-
'&&':
|
|
56
|
-
'>':
|
|
57
|
-
'>=':
|
|
58
|
-
'&':
|
|
59
|
-
'/':
|
|
60
|
-
'==':
|
|
61
|
-
'===':
|
|
62
|
-
'<':
|
|
63
|
-
'<=':
|
|
64
|
-
'-':
|
|
65
|
-
'%':
|
|
66
|
-
'*':
|
|
67
|
-
'!=':
|
|
68
|
-
'!==':
|
|
69
|
-
'||':
|
|
70
|
-
'+':
|
|
71
|
-
'??':
|
|
36
|
+
'&&': typescript_1.default.SyntaxKind.AmpersandAmpersandToken,
|
|
37
|
+
'>': typescript_1.default.SyntaxKind.GreaterThanToken,
|
|
38
|
+
'>=': typescript_1.default.SyntaxKind.GreaterThanEqualsToken,
|
|
39
|
+
'&': typescript_1.default.SyntaxKind.AmpersandToken,
|
|
40
|
+
'/': typescript_1.default.SyntaxKind.SlashToken,
|
|
41
|
+
'==': typescript_1.default.SyntaxKind.EqualsEqualsToken,
|
|
42
|
+
'===': typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken,
|
|
43
|
+
'<': typescript_1.default.SyntaxKind.LessThanToken,
|
|
44
|
+
'<=': typescript_1.default.SyntaxKind.LessThanEqualsToken,
|
|
45
|
+
'-': typescript_1.default.SyntaxKind.MinusToken,
|
|
46
|
+
'%': typescript_1.default.SyntaxKind.PercentToken,
|
|
47
|
+
'*': typescript_1.default.SyntaxKind.AsteriskToken,
|
|
48
|
+
'!=': typescript_1.default.SyntaxKind.ExclamationEqualsToken,
|
|
49
|
+
'!==': typescript_1.default.SyntaxKind.ExclamationEqualsEqualsToken,
|
|
50
|
+
'||': typescript_1.default.SyntaxKind.BarBarToken,
|
|
51
|
+
'+': typescript_1.default.SyntaxKind.PlusToken,
|
|
52
|
+
'??': typescript_1.default.SyntaxKind.QuestionQuestionToken,
|
|
72
53
|
};
|
|
73
54
|
const VAR_TYPES = {
|
|
74
|
-
const:
|
|
75
|
-
let:
|
|
76
|
-
var:
|
|
55
|
+
const: typescript_1.default.NodeFlags.Const,
|
|
56
|
+
let: typescript_1.default.NodeFlags.Let,
|
|
57
|
+
var: typescript_1.default.NodeFlags.None,
|
|
77
58
|
};
|
|
78
59
|
/**
|
|
79
60
|
* A TypeScript flavoured implementation of the AstFactory.
|
|
@@ -83,28 +64,28 @@ class TypeScriptAstFactory {
|
|
|
83
64
|
this.annotateForClosureCompiler = annotateForClosureCompiler;
|
|
84
65
|
this.externalSourceFiles = new Map();
|
|
85
66
|
this.attachComments = attachComments;
|
|
86
|
-
this.createArrayLiteral =
|
|
87
|
-
this.createElementAccess =
|
|
88
|
-
this.createExpressionStatement =
|
|
89
|
-
this.createIdentifier =
|
|
90
|
-
this.createParenthesizedExpression =
|
|
91
|
-
this.createPropertyAccess =
|
|
92
|
-
this.createThrowStatement =
|
|
93
|
-
this.createTypeOfExpression =
|
|
67
|
+
this.createArrayLiteral = typescript_1.default.factory.createArrayLiteralExpression;
|
|
68
|
+
this.createElementAccess = typescript_1.default.factory.createElementAccessExpression;
|
|
69
|
+
this.createExpressionStatement = typescript_1.default.factory.createExpressionStatement;
|
|
70
|
+
this.createIdentifier = typescript_1.default.factory.createIdentifier;
|
|
71
|
+
this.createParenthesizedExpression = typescript_1.default.factory.createParenthesizedExpression;
|
|
72
|
+
this.createPropertyAccess = typescript_1.default.factory.createPropertyAccessExpression;
|
|
73
|
+
this.createThrowStatement = typescript_1.default.factory.createThrowStatement;
|
|
74
|
+
this.createTypeOfExpression = typescript_1.default.factory.createTypeOfExpression;
|
|
94
75
|
}
|
|
95
76
|
createAssignment(target, value) {
|
|
96
|
-
return
|
|
77
|
+
return typescript_1.default.factory.createBinaryExpression(target, typescript_1.default.SyntaxKind.EqualsToken, value);
|
|
97
78
|
}
|
|
98
79
|
createBinaryExpression(leftOperand, operator, rightOperand) {
|
|
99
|
-
return
|
|
80
|
+
return typescript_1.default.factory.createBinaryExpression(leftOperand, BINARY_OPERATORS[operator], rightOperand);
|
|
100
81
|
}
|
|
101
82
|
createBlock(body) {
|
|
102
|
-
return
|
|
83
|
+
return typescript_1.default.factory.createBlock(body);
|
|
103
84
|
}
|
|
104
85
|
createCallExpression(callee, args, pure) {
|
|
105
|
-
const call =
|
|
86
|
+
const call = typescript_1.default.factory.createCallExpression(callee, undefined, args);
|
|
106
87
|
if (pure) {
|
|
107
|
-
|
|
88
|
+
typescript_1.default.addSyntheticLeadingComment(call, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, this.annotateForClosureCompiler
|
|
108
89
|
? PureAnnotation.CLOSURE
|
|
109
90
|
: PureAnnotation.TERSER,
|
|
110
91
|
/* trailing newline */ false);
|
|
@@ -112,57 +93,57 @@ class TypeScriptAstFactory {
|
|
|
112
93
|
return call;
|
|
113
94
|
}
|
|
114
95
|
createConditional(condition, whenTrue, whenFalse) {
|
|
115
|
-
return
|
|
96
|
+
return typescript_1.default.factory.createConditionalExpression(condition, undefined, whenTrue, undefined, whenFalse);
|
|
116
97
|
}
|
|
117
98
|
createFunctionDeclaration(functionName, parameters, body) {
|
|
118
|
-
if (!
|
|
119
|
-
throw new Error(`Invalid syntax, expected a block, but got ${
|
|
99
|
+
if (!typescript_1.default.isBlock(body)) {
|
|
100
|
+
throw new Error(`Invalid syntax, expected a block, but got ${typescript_1.default.SyntaxKind[body.kind]}.`);
|
|
120
101
|
}
|
|
121
|
-
return
|
|
102
|
+
return (0, ts_compatibility_1.createFunctionDeclaration)(undefined, undefined, functionName, undefined, parameters.map((param) => (0, ts_compatibility_1.createParameterDeclaration)(undefined, undefined, param)), undefined, body);
|
|
122
103
|
}
|
|
123
104
|
createFunctionExpression(functionName, parameters, body) {
|
|
124
|
-
if (!
|
|
125
|
-
throw new Error(`Invalid syntax, expected a block, but got ${
|
|
105
|
+
if (!typescript_1.default.isBlock(body)) {
|
|
106
|
+
throw new Error(`Invalid syntax, expected a block, but got ${typescript_1.default.SyntaxKind[body.kind]}.`);
|
|
126
107
|
}
|
|
127
|
-
return
|
|
108
|
+
return typescript_1.default.factory.createFunctionExpression(undefined, undefined, functionName !== null && functionName !== void 0 ? functionName : undefined, undefined, parameters.map((param) => (0, ts_compatibility_1.createParameterDeclaration)(undefined, undefined, param)), undefined, body);
|
|
128
109
|
}
|
|
129
110
|
createIfStatement(condition, thenStatement, elseStatement) {
|
|
130
|
-
return
|
|
111
|
+
return typescript_1.default.factory.createIfStatement(condition, thenStatement, elseStatement !== null && elseStatement !== void 0 ? elseStatement : undefined);
|
|
131
112
|
}
|
|
132
113
|
createLiteral(value) {
|
|
133
114
|
if (value === undefined) {
|
|
134
|
-
return
|
|
115
|
+
return typescript_1.default.factory.createIdentifier('undefined');
|
|
135
116
|
}
|
|
136
117
|
else if (value === null) {
|
|
137
|
-
return
|
|
118
|
+
return typescript_1.default.factory.createNull();
|
|
138
119
|
}
|
|
139
120
|
else if (typeof value === 'boolean') {
|
|
140
|
-
return value ?
|
|
121
|
+
return value ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse();
|
|
141
122
|
}
|
|
142
123
|
else if (typeof value === 'number') {
|
|
143
|
-
return
|
|
124
|
+
return typescript_1.default.factory.createNumericLiteral(value);
|
|
144
125
|
}
|
|
145
126
|
else {
|
|
146
|
-
return
|
|
127
|
+
return typescript_1.default.factory.createStringLiteral(value);
|
|
147
128
|
}
|
|
148
129
|
}
|
|
149
130
|
createNewExpression(expression, args) {
|
|
150
|
-
return
|
|
131
|
+
return typescript_1.default.factory.createNewExpression(expression, undefined, args);
|
|
151
132
|
}
|
|
152
133
|
createObjectLiteral(properties) {
|
|
153
|
-
return
|
|
154
|
-
?
|
|
155
|
-
:
|
|
134
|
+
return typescript_1.default.factory.createObjectLiteralExpression(properties.map((prop) => typescript_1.default.factory.createPropertyAssignment(prop.quoted
|
|
135
|
+
? typescript_1.default.factory.createStringLiteral(prop.propertyName)
|
|
136
|
+
: typescript_1.default.factory.createIdentifier(prop.propertyName), prop.value)));
|
|
156
137
|
}
|
|
157
138
|
createReturnStatement(expression) {
|
|
158
|
-
return
|
|
139
|
+
return typescript_1.default.factory.createReturnStatement(expression !== null && expression !== void 0 ? expression : undefined);
|
|
159
140
|
}
|
|
160
141
|
createTaggedTemplate(tag, template) {
|
|
161
142
|
let templateLiteral;
|
|
162
143
|
const length = template.elements.length;
|
|
163
144
|
const head = template.elements[0];
|
|
164
145
|
if (length === 1) {
|
|
165
|
-
templateLiteral =
|
|
146
|
+
templateLiteral = typescript_1.default.factory.createNoSubstitutionTemplateLiteral(head.cooked, head.raw);
|
|
166
147
|
}
|
|
167
148
|
else {
|
|
168
149
|
const spans = [];
|
|
@@ -173,7 +154,7 @@ class TypeScriptAstFactory {
|
|
|
173
154
|
if (range !== null) {
|
|
174
155
|
this.setSourceMapRange(middle, range);
|
|
175
156
|
}
|
|
176
|
-
spans.push(
|
|
157
|
+
spans.push(typescript_1.default.factory.createTemplateSpan(template.expressions[i - 1], middle));
|
|
177
158
|
}
|
|
178
159
|
// Create the tail part
|
|
179
160
|
const resolvedExpression = template.expressions[length - 2];
|
|
@@ -182,21 +163,21 @@ class TypeScriptAstFactory {
|
|
|
182
163
|
if (templatePart.range !== null) {
|
|
183
164
|
this.setSourceMapRange(templateTail, templatePart.range);
|
|
184
165
|
}
|
|
185
|
-
spans.push(
|
|
166
|
+
spans.push(typescript_1.default.factory.createTemplateSpan(resolvedExpression, templateTail));
|
|
186
167
|
// Put it all together
|
|
187
|
-
templateLiteral =
|
|
168
|
+
templateLiteral = typescript_1.default.factory.createTemplateExpression(typescript_1.default.factory.createTemplateHead(head.cooked, head.raw), spans);
|
|
188
169
|
}
|
|
189
170
|
if (head.range !== null) {
|
|
190
171
|
this.setSourceMapRange(templateLiteral, head.range);
|
|
191
172
|
}
|
|
192
|
-
return
|
|
173
|
+
return typescript_1.default.factory.createTaggedTemplateExpression(tag, undefined, templateLiteral);
|
|
193
174
|
}
|
|
194
175
|
createUnaryExpression(operator, operand) {
|
|
195
|
-
return
|
|
176
|
+
return typescript_1.default.factory.createPrefixUnaryExpression(UNARY_OPERATORS[operator], operand);
|
|
196
177
|
}
|
|
197
178
|
createVariableDeclaration(variableName, initializer, type) {
|
|
198
|
-
return
|
|
199
|
-
|
|
179
|
+
return typescript_1.default.factory.createVariableStatement(undefined, typescript_1.default.factory.createVariableDeclarationList([
|
|
180
|
+
typescript_1.default.factory.createVariableDeclaration(variableName, undefined, undefined, initializer !== null && initializer !== void 0 ? initializer : undefined),
|
|
200
181
|
], VAR_TYPES[type]));
|
|
201
182
|
}
|
|
202
183
|
setSourceMapRange(node, sourceMapRange) {
|
|
@@ -205,10 +186,10 @@ class TypeScriptAstFactory {
|
|
|
205
186
|
}
|
|
206
187
|
const url = sourceMapRange.url;
|
|
207
188
|
if (!this.externalSourceFiles.has(url)) {
|
|
208
|
-
this.externalSourceFiles.set(url,
|
|
189
|
+
this.externalSourceFiles.set(url, typescript_1.default.createSourceMapSource(url, sourceMapRange.content, (pos) => pos));
|
|
209
190
|
}
|
|
210
191
|
const source = this.externalSourceFiles.get(url);
|
|
211
|
-
|
|
192
|
+
typescript_1.default.setSourceMapRange(node, {
|
|
212
193
|
pos: sourceMapRange.start.offset,
|
|
213
194
|
end: sourceMapRange.end.offset,
|
|
214
195
|
source,
|
|
@@ -220,16 +201,16 @@ exports.TypeScriptAstFactory = TypeScriptAstFactory;
|
|
|
220
201
|
// HACK: Use this in place of `ts.createTemplateMiddle()`.
|
|
221
202
|
// Revert once https://github.com/microsoft/TypeScript/issues/35374 is fixed.
|
|
222
203
|
function createTemplateMiddle(cooked, raw) {
|
|
223
|
-
const node =
|
|
224
|
-
node.kind =
|
|
204
|
+
const node = typescript_1.default.factory.createTemplateHead(cooked, raw);
|
|
205
|
+
node.kind = typescript_1.default.SyntaxKind.TemplateMiddle;
|
|
225
206
|
return node;
|
|
226
207
|
}
|
|
227
208
|
exports.createTemplateMiddle = createTemplateMiddle;
|
|
228
209
|
// HACK: Use this in place of `ts.createTemplateTail()`.
|
|
229
210
|
// Revert once https://github.com/microsoft/TypeScript/issues/35374 is fixed.
|
|
230
211
|
function createTemplateTail(cooked, raw) {
|
|
231
|
-
const node =
|
|
232
|
-
node.kind =
|
|
212
|
+
const node = typescript_1.default.factory.createTemplateHead(cooked, raw);
|
|
213
|
+
node.kind = typescript_1.default.SyntaxKind.TemplateTail;
|
|
233
214
|
return node;
|
|
234
215
|
}
|
|
235
216
|
exports.createTemplateTail = createTemplateTail;
|
|
@@ -242,14 +223,14 @@ exports.createTemplateTail = createTemplateTail;
|
|
|
242
223
|
function attachComments(statement, leadingComments) {
|
|
243
224
|
for (const comment of leadingComments) {
|
|
244
225
|
const commentKind = comment.multiline
|
|
245
|
-
?
|
|
246
|
-
:
|
|
226
|
+
? typescript_1.default.SyntaxKind.MultiLineCommentTrivia
|
|
227
|
+
: typescript_1.default.SyntaxKind.SingleLineCommentTrivia;
|
|
247
228
|
if (comment.multiline) {
|
|
248
|
-
|
|
229
|
+
typescript_1.default.addSyntheticLeadingComment(statement, commentKind, comment.toString(), comment.trailingNewline);
|
|
249
230
|
}
|
|
250
231
|
else {
|
|
251
232
|
for (const line of comment.toString().split('\n')) {
|
|
252
|
-
|
|
233
|
+
typescript_1.default.addSyntheticLeadingComment(statement, commentKind, line, comment.trailingNewline);
|
|
253
234
|
}
|
|
254
235
|
}
|
|
255
236
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import * as o from
|
|
9
|
-
import
|
|
10
|
-
import { ImportGenerator } from
|
|
11
|
-
import { TranslatorOptions } from
|
|
8
|
+
import * as o from 'static-injector/transform/compiler';
|
|
9
|
+
import ts from 'typescript';
|
|
10
|
+
import { ImportGenerator } from './api/import_generator';
|
|
11
|
+
import { TranslatorOptions } from './translator';
|
|
12
12
|
export declare function translateExpression(expression: o.Expression, imports: ImportGenerator<ts.Expression>, options?: TranslatorOptions<ts.Expression>): ts.Expression;
|
|
13
13
|
export declare function translateStatement(statement: o.Statement, imports: ImportGenerator<ts.Expression>, options?: TranslatorOptions<ts.Expression>): ts.Statement;
|
|
@@ -6,146 +6,40 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import ts from 'typescript';
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/** Type of `ts.factory.updateParameterDeclaration` in TS 4.8+. */
|
|
12
|
-
declare type Ts48UpdateParameterDeclarationFn = (node: ts.ParameterDeclaration, modifiers: readonly ModifierLike[] | undefined, dotDotDotToken: ts.DotDotDotToken | undefined, name: string | ts.BindingName, questionToken: ts.QuestionToken | undefined, type: ts.TypeNode | undefined, initializer: ts.Expression | undefined) => ts.ParameterDeclaration;
|
|
9
|
+
/** Type of `ts.factory.CreateParameterDeclaration` in TS 4.9+. */
|
|
10
|
+
type Ts49CreateParameterDeclarationFn = (modifiers: readonly ts.ModifierLike[] | undefined, dotDotDotToken: ts.DotDotDotToken | undefined, name: string | ts.BindingName, questionToken?: ts.QuestionToken | undefined, type?: ts.TypeNode | undefined, initializer?: ts.Expression) => ts.ParameterDeclaration;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Creates a `ts.ParameterDeclaration` declaration.
|
|
15
13
|
*
|
|
16
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.
|
|
14
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
|
|
17
15
|
* We should remove it once we have dropped support for the older versions.
|
|
18
16
|
*/
|
|
19
|
-
export declare const
|
|
20
|
-
/** Type of `ts.factory.
|
|
21
|
-
|
|
17
|
+
export declare const createParameterDeclaration: Ts49CreateParameterDeclarationFn;
|
|
18
|
+
/** Type of `ts.factory.createImportDeclaration` in TS 4.9+. */
|
|
19
|
+
type Ts49CreateImportDeclarationFn = (modifiers: readonly ts.Modifier[] | undefined, importClause: ts.ImportClause | undefined, moduleSpecifier: ts.Expression, assertClause?: ts.AssertClause) => ts.ImportDeclaration;
|
|
22
20
|
/**
|
|
23
|
-
*
|
|
21
|
+
* Creates a `ts.ImportDeclaration` declaration.
|
|
24
22
|
*
|
|
25
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.
|
|
23
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
|
|
26
24
|
* We should remove it once we have dropped support for the older versions.
|
|
27
25
|
*/
|
|
28
|
-
export declare const
|
|
29
|
-
/** Type of `ts.factory.
|
|
30
|
-
|
|
26
|
+
export declare const createImportDeclaration: Ts49CreateImportDeclarationFn;
|
|
27
|
+
/** Type of `ts.factory.createFunctionDeclaration` in TS 4.9+. */
|
|
28
|
+
type Ts49CreateFunctionDeclarationFn = (modifiers: readonly ts.ModifierLike[] | undefined, asteriskToken: ts.AsteriskToken | undefined, name: string | ts.Identifier | undefined, typeParameters: readonly ts.TypeParameterDeclaration[] | undefined, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode | undefined, body: ts.Block | undefined) => ts.FunctionDeclaration;
|
|
31
29
|
/**
|
|
32
|
-
*
|
|
30
|
+
* Creates a `ts.FunctionDeclaration` declaration.
|
|
33
31
|
*
|
|
34
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.
|
|
32
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
|
|
35
33
|
* We should remove it once we have dropped support for the older versions.
|
|
36
34
|
*/
|
|
37
|
-
export declare const
|
|
38
|
-
/** Type of `ts.factory.
|
|
39
|
-
|
|
35
|
+
export declare const createFunctionDeclaration: Ts49CreateFunctionDeclarationFn;
|
|
36
|
+
/** Type of `ts.factory.createIndexSignature` in TS 4.9+. */
|
|
37
|
+
type Ts49CreateIndexSignatureFn = (modifiers: readonly ts.Modifier[] | undefined, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode) => ts.IndexSignatureDeclaration;
|
|
40
38
|
/**
|
|
41
|
-
* Creates a `ts.
|
|
39
|
+
* Creates a `ts.IndexSignatureDeclaration` declaration.
|
|
42
40
|
*
|
|
43
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.
|
|
41
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
|
|
44
42
|
* We should remove it once we have dropped support for the older versions.
|
|
45
43
|
*/
|
|
46
|
-
export declare const
|
|
47
|
-
/** Type of `ts.factory.updateMethodDeclaration` in TS 4.8+. */
|
|
48
|
-
declare type Ts48UpdateMethodDeclarationFn = (node: ts.MethodDeclaration, modifiers: readonly ModifierLike[] | undefined, asteriskToken: ts.AsteriskToken | undefined, name: ts.PropertyName, questionToken: ts.QuestionToken | undefined, typeParameters: readonly ts.TypeParameterDeclaration[] | undefined, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode | undefined, body: ts.Block | undefined) => ts.MethodDeclaration;
|
|
49
|
-
/**
|
|
50
|
-
* Updates a `ts.MethodDeclaration` declaration.
|
|
51
|
-
*
|
|
52
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
53
|
-
* We should remove it once we have dropped support for the older versions.
|
|
54
|
-
*/
|
|
55
|
-
export declare const updateMethodDeclaration: Ts48UpdateMethodDeclarationFn;
|
|
56
|
-
/** Type of `ts.factory.createMethodDeclaration` in TS 4.8+. */
|
|
57
|
-
declare type Ts48CreateMethodDeclarationFn = (modifiers: readonly ModifierLike[] | undefined, asteriskToken: ts.AsteriskToken | undefined, name: ts.PropertyName, questionToken: ts.QuestionToken | undefined, typeParameters: readonly ts.TypeParameterDeclaration[] | undefined, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode | undefined, body: ts.Block | undefined) => ts.MethodDeclaration;
|
|
58
|
-
/**
|
|
59
|
-
* Creates a `ts.MethodDeclaration` declaration.
|
|
60
|
-
*
|
|
61
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
62
|
-
* We should remove it once we have dropped support for the older versions.
|
|
63
|
-
*/
|
|
64
|
-
export declare const createMethodDeclaration: Ts48CreateMethodDeclarationFn;
|
|
65
|
-
/** Type of `ts.factory.updatePropertyDeclaration` in TS 4.8+. */
|
|
66
|
-
declare type Ts48UpdatePropertyDeclarationFn = (node: ts.PropertyDeclaration, modifiers: readonly ModifierLike[] | undefined, name: string | ts.PropertyName, questionOrExclamationToken: ts.QuestionToken | ts.ExclamationToken | undefined, type: ts.TypeNode | undefined, initializer: ts.Expression | undefined) => ts.PropertyDeclaration;
|
|
67
|
-
/**
|
|
68
|
-
* Updates a `ts.PropertyDeclaration` declaration.
|
|
69
|
-
*
|
|
70
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
71
|
-
* We should remove it once we have dropped support for the older versions.
|
|
72
|
-
*/
|
|
73
|
-
export declare const updatePropertyDeclaration: Ts48UpdatePropertyDeclarationFn;
|
|
74
|
-
/** Type of `ts.factory.createPropertyDeclaration` in TS 4.8+. */
|
|
75
|
-
declare type Ts48CreatePropertyDeclarationFn = (modifiers: readonly ModifierLike[] | undefined, name: string | ts.PropertyName, questionOrExclamationToken: ts.QuestionToken | ts.ExclamationToken | undefined, type: ts.TypeNode | undefined, initializer: ts.Expression | undefined) => ts.PropertyDeclaration;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a `ts.PropertyDeclaration` declaration.
|
|
78
|
-
*
|
|
79
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
80
|
-
* We should remove it once we have dropped support for the older versions.
|
|
81
|
-
*/
|
|
82
|
-
export declare const createPropertyDeclaration: Ts48CreatePropertyDeclarationFn;
|
|
83
|
-
/** Type of `ts.factory.updateGetAccessorDeclaration` in TS 4.8+. */
|
|
84
|
-
declare type Ts48UpdateGetAccessorDeclarationFn = (node: ts.GetAccessorDeclaration, modifiers: readonly ModifierLike[] | undefined, name: ts.PropertyName, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode | undefined, body: ts.Block | undefined) => ts.GetAccessorDeclaration;
|
|
85
|
-
/**
|
|
86
|
-
* Updates a `ts.GetAccessorDeclaration` declaration.
|
|
87
|
-
*
|
|
88
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
89
|
-
* We should remove it once we have dropped support for the older versions.
|
|
90
|
-
*/
|
|
91
|
-
export declare const updateGetAccessorDeclaration: Ts48UpdateGetAccessorDeclarationFn;
|
|
92
|
-
/** Type of `ts.factory.createGetAccessorDeclaration` in TS 4.8+. */
|
|
93
|
-
declare type Ts48CreateGetAccessorDeclarationFn = (modifiers: readonly ModifierLike[] | undefined, name: ts.PropertyName, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode | undefined, body: ts.Block | undefined) => ts.GetAccessorDeclaration;
|
|
94
|
-
/**
|
|
95
|
-
* Creates a `ts.GetAccessorDeclaration` declaration.
|
|
96
|
-
*
|
|
97
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
98
|
-
* We should remove it once we have dropped support for the older versions.
|
|
99
|
-
*/
|
|
100
|
-
export declare const createGetAccessorDeclaration: Ts48CreateGetAccessorDeclarationFn;
|
|
101
|
-
/** Type of `ts.factory.updateSetAccessorDeclaration` in TS 4.8+. */
|
|
102
|
-
declare type Ts48UpdateSetAccessorDeclarationFn = (node: ts.SetAccessorDeclaration, modifiers: readonly ModifierLike[] | undefined, name: ts.PropertyName, parameters: readonly ts.ParameterDeclaration[], body: ts.Block | undefined) => ts.SetAccessorDeclaration;
|
|
103
|
-
/**
|
|
104
|
-
* Updates a `ts.GetAccessorDeclaration` declaration.
|
|
105
|
-
*
|
|
106
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
107
|
-
* We should remove it once we have dropped support for the older versions.
|
|
108
|
-
*/
|
|
109
|
-
export declare const updateSetAccessorDeclaration: Ts48UpdateSetAccessorDeclarationFn;
|
|
110
|
-
/** Type of `ts.factory.createSetAccessorDeclaration` in TS 4.8+. */
|
|
111
|
-
declare type Ts48CreateSetAccessorDeclarationFn = (modifiers: readonly ModifierLike[] | undefined, name: ts.PropertyName, parameters: readonly ts.ParameterDeclaration[], body: ts.Block | undefined) => ts.SetAccessorDeclaration;
|
|
112
|
-
/**
|
|
113
|
-
* Creates a `ts.GetAccessorDeclaration` declaration.
|
|
114
|
-
*
|
|
115
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
116
|
-
* We should remove it once we have dropped support for the older versions.
|
|
117
|
-
*/
|
|
118
|
-
export declare const createSetAccessorDeclaration: Ts48CreateSetAccessorDeclarationFn;
|
|
119
|
-
/** Type of `ts.factory.updateConstructorDeclaration` in TS 4.8+. */
|
|
120
|
-
declare type Ts48UpdateConstructorDeclarationFn = (node: ts.ConstructorDeclaration, modifiers: readonly ts.Modifier[] | undefined, parameters: readonly ts.ParameterDeclaration[], body: ts.Block | undefined) => ts.ConstructorDeclaration;
|
|
121
|
-
/**
|
|
122
|
-
* Updates a `ts.ConstructorDeclaration` declaration.
|
|
123
|
-
*
|
|
124
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
125
|
-
* We should remove it once we have dropped support for the older versions.
|
|
126
|
-
*/
|
|
127
|
-
export declare const updateConstructorDeclaration: Ts48UpdateConstructorDeclarationFn;
|
|
128
|
-
/**
|
|
129
|
-
* Gets the decorators that have been applied to a node.
|
|
130
|
-
*
|
|
131
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
132
|
-
* We should remove it once we have dropped support for the older versions.
|
|
133
|
-
*/
|
|
134
|
-
export declare const getDecorators: (node: ts.Node) => readonly ts.Decorator[] | undefined;
|
|
135
|
-
/**
|
|
136
|
-
* Gets the modifiers that have been set on a node.
|
|
137
|
-
*
|
|
138
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
139
|
-
* We should remove it once we have dropped support for the older versions.
|
|
140
|
-
*/
|
|
141
|
-
export declare const getModifiers: (node: ts.Node) => readonly ts.Modifier[] | undefined;
|
|
142
|
-
/**
|
|
143
|
-
* Combines an optional array of decorators with an optional array of modifiers into a single
|
|
144
|
-
* `ts.ModifierLike` array. Used in version of TypeScript after 4.8 where the `decorators` and
|
|
145
|
-
* `modifiers` arrays have been combined.
|
|
146
|
-
*
|
|
147
|
-
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
148
|
-
* We should remove it once we have dropped support for the older versions.
|
|
149
|
-
*/
|
|
150
|
-
export declare function combineModifiers(decorators: readonly ts.Decorator[] | undefined, modifiers: readonly ModifierLike[] | undefined): readonly ModifierLike[] | undefined;
|
|
44
|
+
export declare const createIndexSignature: Ts49CreateIndexSignatureFn;
|
|
151
45
|
export {};
|