static-injector 1.0.10 → 2.1.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/import/commonjs/index.js +337 -124
- package/import/es2015/di/create_injector.js +30 -0
- package/import/es2015/di/initializer_token.js +15 -0
- package/import/es2015/di/inject_switch.js +27 -6
- package/import/es2015/di/injection_token.js +6 -0
- package/import/es2015/di/injector.js +6 -8
- package/import/es2015/di/injector_compatibility.js +90 -34
- package/import/es2015/di/injector_token.js +1 -1
- package/import/es2015/di/interface/defs.js +39 -0
- package/import/es2015/di/interface/injector.js +1 -0
- package/import/es2015/di/internal_tokens.js +9 -0
- package/import/es2015/di/metadata.js +4 -4
- package/import/es2015/di/provider_collection.js +49 -0
- package/import/es2015/di/r3_injector.js +102 -72
- package/import/es2015/di/scope.js +2 -2
- package/import/es2015/index.js +1 -1
- package/import/es2015/render3/errors_di.js +1 -1
- package/import/fesm2015/index.js +328 -114
- package/import/typings/di/create_injector.d.ts +23 -0
- package/import/typings/di/initializer_token.d.ts +15 -0
- package/import/typings/di/inject_switch.d.ts +7 -2
- package/import/typings/{decorator → di}/injectable.d.ts +2 -2
- package/import/typings/di/injection_token.d.ts +4 -0
- package/import/typings/di/injector.d.ts +20 -7
- package/import/typings/di/injector_compatibility.d.ts +42 -21
- package/import/typings/di/interface/defs.d.ts +10 -0
- package/import/typings/di/interface/injector.d.ts +26 -0
- package/import/typings/di/interface/provider.d.ts +3 -8
- package/import/typings/di/internal_tokens.d.ts +10 -0
- package/import/typings/di/provider_collection.d.ts +30 -0
- package/import/typings/di/provider_token.d.ts +1 -1
- package/import/typings/di/r3_injector.d.ts +68 -37
- package/import/typings/di/scope.d.ts +3 -2
- package/import/typings/index.d.ts +1 -1
- package/import/typings/render3/definition_factory.d.ts +1 -1
- package/package.json +5 -3
- package/{import/es2015/decorator/interface/provider.js → transform/compiler/compiler.d.ts} +1 -1
- package/transform/compiler/compiler.js +28 -0
- package/transform/compiler/index.d.ts +8 -5
- package/transform/compiler/index.js +17 -6
- 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/injectable_compiler_2.d.ts +7 -36
- package/transform/compiler/src/injectable_compiler_2.js +20 -23
- package/transform/compiler/src/output/output_ast.d.ts +30 -109
- package/transform/compiler/src/output/output_ast.js +66 -188
- 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 +46 -61
- package/transform/compiler/src/render3/util.d.ts +64 -0
- package/transform/compiler/src/render3/util.js +52 -9
- package/transform/compiler/src/render3/view/util.d.ts +0 -8
- package/transform/compiler/src/render3/view/util.js +5 -9
- 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 +3 -3
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +4 -34
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +181 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +46 -53
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -1
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +12 -1
- 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 +12 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +13 -14
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +8 -25
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +44 -55
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +55 -69
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -23
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +16 -31
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +12 -1
- 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 +4 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +5 -21
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -6
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +6 -18
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +83 -90
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +8 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +45 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +86 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -27
- package/transform/index.js +5 -1
- package/transform/injectable-transform.js +59 -38
- package/import/typings/decorator/interface/provider.d.ts +0 -312
- package/transform/compiler/src/render3/partial/util.d.ts +0 -16
- package/transform/compiler/src/render3/partial/util.js +0 -44
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +0 -370
- /package/import/es2015/{decorator → di}/injectable.js +0 -0
|
@@ -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 { Expression, Statement, Type } from
|
|
9
|
-
import
|
|
10
|
-
import { ClassDeclaration, Decorator } from
|
|
8
|
+
import { Expression, Statement, Type } from 'static-injector/transform/compiler';
|
|
9
|
+
import ts from 'typescript';
|
|
10
|
+
import { ClassDeclaration, Decorator } from '../../reflection';
|
|
11
11
|
/**
|
|
12
12
|
* A set of options which can be passed to a `DecoratorHandler` by a consumer, to tailor the output
|
|
13
13
|
* of compilation beyond the decorators themselves.
|
|
@@ -39,7 +39,7 @@ export declare enum HandlerFlags {
|
|
|
39
39
|
* @param `A` The type of analysis metadata produced by `analyze`.
|
|
40
40
|
* @param `R` The type of resolution metadata produced by `resolve`.
|
|
41
41
|
*/
|
|
42
|
-
export interface DecoratorHandler<D, A,
|
|
42
|
+
export interface DecoratorHandler<D, A, R> {
|
|
43
43
|
/**
|
|
44
44
|
* Scan a set of reflected decorators and determine if this handler is responsible for compilation
|
|
45
45
|
* of one of them.
|
|
@@ -5,8 +5,8 @@
|
|
|
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
|
|
9
|
-
import { ImportManager } from
|
|
8
|
+
import ts from 'typescript';
|
|
9
|
+
import { ImportManager } from '../../translator';
|
|
10
10
|
/**
|
|
11
11
|
* Adds extra imports in the import manage for this source file, after the existing imports
|
|
12
12
|
* and before the module body.
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
4
|
};
|
|
21
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
6
|
exports.addImports = void 0;
|
|
@@ -27,7 +11,8 @@ exports.addImports = void 0;
|
|
|
27
11
|
* Use of this source code is governed by an MIT-style license that can be
|
|
28
12
|
* found in the LICENSE file at https://angular.io/license
|
|
29
13
|
*/
|
|
30
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
const ts_compatibility_1 = require("../../ts_compatibility");
|
|
31
16
|
/**
|
|
32
17
|
* Adds extra imports in the import manage for this source file, after the existing imports
|
|
33
18
|
* and before the module body.
|
|
@@ -36,15 +21,15 @@ const ts = __importStar(require("typescript"));
|
|
|
36
21
|
function addImports(importManager, sf, extraStatements = []) {
|
|
37
22
|
// Generate the import statements to prepend.
|
|
38
23
|
const addedImports = importManager.getAllImports(sf.fileName).map((i) => {
|
|
39
|
-
const qualifier =
|
|
40
|
-
const importClause =
|
|
24
|
+
const qualifier = typescript_1.default.factory.createIdentifier(i.qualifier.text);
|
|
25
|
+
const importClause = typescript_1.default.factory.createImportClause(
|
|
26
|
+
/* isTypeOnly */ false,
|
|
41
27
|
/* name */ undefined,
|
|
42
|
-
/* namedBindings */
|
|
43
|
-
const decl =
|
|
44
|
-
/* decorators */ undefined,
|
|
28
|
+
/* namedBindings */ typescript_1.default.factory.createNamespaceImport(qualifier));
|
|
29
|
+
const decl = (0, ts_compatibility_1.createImportDeclaration)(
|
|
45
30
|
/* modifiers */ undefined,
|
|
46
31
|
/* importClause */ importClause,
|
|
47
|
-
/* moduleSpecifier */
|
|
32
|
+
/* moduleSpecifier */ typescript_1.default.factory.createStringLiteral(i.specifier));
|
|
48
33
|
// Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
|
|
49
34
|
// transforms such as tsickle to properly process references to this import.
|
|
50
35
|
//
|
|
@@ -53,7 +38,7 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
53
38
|
//
|
|
54
39
|
// TODO(alxhub): add a test for this when tsickle is updated externally to depend on this
|
|
55
40
|
// behavior.
|
|
56
|
-
|
|
41
|
+
typescript_1.default.setOriginalNode(i.qualifier, decl);
|
|
57
42
|
return decl;
|
|
58
43
|
});
|
|
59
44
|
// Filter out the existing imports and the source file body. All new statements
|
|
@@ -65,8 +50,8 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
65
50
|
// If we prepend imports, we also prepend NotEmittedStatement to use it as an anchor
|
|
66
51
|
// for @fileoverview Closure annotation. If there is no @fileoverview annotations, this
|
|
67
52
|
// statement would be a noop.
|
|
68
|
-
const fileoverviewAnchorStmt =
|
|
69
|
-
return
|
|
53
|
+
const fileoverviewAnchorStmt = typescript_1.default.factory.createNotEmittedStatement(sf);
|
|
54
|
+
return typescript_1.default.factory.updateSourceFile(sf, typescript_1.default.factory.createNodeArray([
|
|
70
55
|
fileoverviewAnchorStmt,
|
|
71
56
|
...existingImports,
|
|
72
57
|
...addedImports,
|
|
@@ -78,7 +63,7 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
78
63
|
}
|
|
79
64
|
exports.addImports = addImports;
|
|
80
65
|
function isImportStatement(stmt) {
|
|
81
|
-
return (
|
|
82
|
-
|
|
83
|
-
|
|
66
|
+
return (typescript_1.default.isImportDeclaration(stmt) ||
|
|
67
|
+
typescript_1.default.isImportEqualsDeclaration(stmt) ||
|
|
68
|
+
typescript_1.default.isNamespaceImport(stmt));
|
|
84
69
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
export * from './src/context';
|
|
9
|
+
export * from './src/translator';
|
|
10
|
+
export * from './src/typescript_ast_factory';
|
|
11
|
+
export * from './src/typescript_translator';
|
|
12
|
+
export * from './src/import_manager';
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
5
16
|
}) : (function(o, m, k, k2) {
|
|
6
17
|
if (k2 === undefined) k2 = k;
|
|
7
18
|
o[k2] = m[k];
|
|
@@ -21,7 +21,7 @@ export interface AstFactory<TStatement, TExpression> {
|
|
|
21
21
|
*/
|
|
22
22
|
attachComments(statement: TStatement, leadingComments: LeadingComment[]): void;
|
|
23
23
|
/**
|
|
24
|
-
* Create a literal array
|
|
24
|
+
* Create a literal array expression (e.g. `[expr1, expr2]`).
|
|
25
25
|
*
|
|
26
26
|
* @param elements a collection of the expressions to appear in each array slot.
|
|
27
27
|
*/
|
|
@@ -51,7 +51,7 @@ export interface AstFactory<TStatement, TExpression> {
|
|
|
51
51
|
* Create an expression that is calling the `callee` with the given `args`.
|
|
52
52
|
*
|
|
53
53
|
* @param callee an expression that evaluates to a function to be called.
|
|
54
|
-
* @param args the
|
|
54
|
+
* @param args the arguments to be passed to the call.
|
|
55
55
|
* @param pure whether to mark the call as pure (having no side-effects).
|
|
56
56
|
*/
|
|
57
57
|
createCallExpression(callee: TExpression, args: TExpression[], pure: boolean): TExpression;
|
|
@@ -198,15 +198,15 @@ export interface AstFactory<TStatement, TExpression> {
|
|
|
198
198
|
/**
|
|
199
199
|
* The type of a variable declaration.
|
|
200
200
|
*/
|
|
201
|
-
export
|
|
201
|
+
export type VariableDeclarationType = 'const' | 'let' | 'var';
|
|
202
202
|
/**
|
|
203
203
|
* The unary operators supported by the `AstFactory`.
|
|
204
204
|
*/
|
|
205
|
-
export
|
|
205
|
+
export type UnaryOperator = '+' | '-' | '!';
|
|
206
206
|
/**
|
|
207
207
|
* The binary operators supported by the `AstFactory`.
|
|
208
208
|
*/
|
|
209
|
-
export
|
|
209
|
+
export type BinaryOperator = '&&' | '>' | '>=' | '&' | '/' | '==' | '===' | '<' | '<=' | '-' | '%' | '*' | '!=' | '!==' | '||' | '+' | '??';
|
|
210
210
|
/**
|
|
211
211
|
* The original location of the start or end of a node created by the `AstFactory`.
|
|
212
212
|
*/
|
|
@@ -5,16 +5,16 @@
|
|
|
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
|
|
9
|
-
import { ImportRewriter } from
|
|
10
|
-
import { ImportGenerator, NamedImport } from
|
|
8
|
+
import ts from 'typescript';
|
|
9
|
+
import { ImportRewriter } from '../../imports';
|
|
10
|
+
import { ImportGenerator, NamedImport } from './api/import_generator';
|
|
11
11
|
/**
|
|
12
12
|
* Information about an import that has been added to a module.
|
|
13
13
|
*/
|
|
14
14
|
export interface Import {
|
|
15
15
|
/** The name of the module that has been imported. */
|
|
16
16
|
specifier: string;
|
|
17
|
-
/** The `ts.
|
|
17
|
+
/** The `ts.Identifier` by which the imported module is known. */
|
|
18
18
|
qualifier: ts.Identifier;
|
|
19
19
|
}
|
|
20
20
|
export declare class ImportManager implements ImportGenerator<ts.Identifier> {
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
4
|
};
|
|
21
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
6
|
exports.ImportManager = void 0;
|
|
@@ -27,10 +11,10 @@ exports.ImportManager = void 0;
|
|
|
27
11
|
* Use of this source code is governed by an MIT-style license that can be
|
|
28
12
|
* found in the LICENSE file at https://angular.io/license
|
|
29
13
|
*/
|
|
30
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
31
15
|
const imports_1 = require("../../imports");
|
|
32
16
|
class ImportManager {
|
|
33
|
-
constructor(rewriter = new imports_1.NoopImportRewriter(), prefix =
|
|
17
|
+
constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i') {
|
|
34
18
|
this.rewriter = rewriter;
|
|
35
19
|
this.prefix = prefix;
|
|
36
20
|
this.specifierToIdentifier = new Map();
|
|
@@ -38,7 +22,7 @@ class ImportManager {
|
|
|
38
22
|
}
|
|
39
23
|
generateNamespaceImport(moduleName) {
|
|
40
24
|
if (!this.specifierToIdentifier.has(moduleName)) {
|
|
41
|
-
this.specifierToIdentifier.set(moduleName,
|
|
25
|
+
this.specifierToIdentifier.set(moduleName, typescript_1.default.factory.createIdentifier(`${this.prefix}${this.nextIndex++}`));
|
|
42
26
|
}
|
|
43
27
|
return this.specifierToIdentifier.get(moduleName);
|
|
44
28
|
}
|
|
@@ -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;
|
|
@@ -27,21 +27,17 @@ export declare class ExpressionTranslatorVisitor<TStatement, TExpression> implem
|
|
|
27
27
|
visitDeclareFunctionStmt(stmt: o.DeclareFunctionStmt, context: Context): TStatement;
|
|
28
28
|
visitExpressionStmt(stmt: o.ExpressionStatement, context: Context): TStatement;
|
|
29
29
|
visitReturnStmt(stmt: o.ReturnStatement, context: Context): TStatement;
|
|
30
|
-
visitDeclareClassStmt(_stmt: o.ClassStmt, _context: Context): never;
|
|
31
30
|
visitIfStmt(stmt: o.IfStmt, context: Context): TStatement;
|
|
32
31
|
visitReadVarExpr(ast: o.ReadVarExpr, _context: Context): TExpression;
|
|
33
32
|
visitWriteVarExpr(expr: o.WriteVarExpr, context: Context): TExpression;
|
|
34
33
|
visitWriteKeyExpr(expr: o.WriteKeyExpr, context: Context): TExpression;
|
|
35
34
|
visitWritePropExpr(expr: o.WritePropExpr, context: Context): TExpression;
|
|
36
|
-
visitInvokeMethodExpr(ast: o.InvokeMethodExpr, context: Context): TExpression;
|
|
37
35
|
visitInvokeFunctionExpr(ast: o.InvokeFunctionExpr, context: Context): TExpression;
|
|
38
36
|
visitInstantiateExpr(ast: o.InstantiateExpr, context: Context): TExpression;
|
|
39
37
|
visitLiteralExpr(ast: o.LiteralExpr, _context: Context): TExpression;
|
|
40
38
|
visitExternalExpr(ast: o.ExternalExpr, _context: Context): TExpression;
|
|
41
39
|
visitConditionalExpr(ast: o.ConditionalExpr, context: Context): TExpression;
|
|
42
40
|
visitNotExpr(ast: o.NotExpr, context: Context): TExpression;
|
|
43
|
-
visitAssertNotNullExpr(ast: o.AssertNotNull, context: Context): TExpression;
|
|
44
|
-
visitCastExpr(ast: o.CastExpr, context: Context): TExpression;
|
|
45
41
|
visitFunctionExpr(ast: o.FunctionExpr, context: Context): TExpression;
|
|
46
42
|
visitBinaryOperatorExpr(ast: o.BinaryOperatorExpr, context: Context): TExpression;
|
|
47
43
|
visitReadPropExpr(ast: o.ReadPropExpr, context: Context): TExpression;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -27,7 +31,7 @@ exports.ExpressionTranslatorVisitor = void 0;
|
|
|
27
31
|
* Use of this source code is governed by an MIT-style license that can be
|
|
28
32
|
* found in the LICENSE file at https://angular.io/license
|
|
29
33
|
*/
|
|
30
|
-
const o = __importStar(require("
|
|
34
|
+
const o = __importStar(require("static-injector/transform/compiler"));
|
|
31
35
|
const UNARY_OPERATORS = new Map([
|
|
32
36
|
[o.UnaryOperator.Minus, '-'],
|
|
33
37
|
[o.UnaryOperator.Plus, '+'],
|
|
@@ -78,9 +82,6 @@ class ExpressionTranslatorVisitor {
|
|
|
78
82
|
visitReturnStmt(stmt, context) {
|
|
79
83
|
return this.attachComments(this.factory.createReturnStatement(stmt.value.visitExpression(this, context.withExpressionMode)), stmt.leadingComments);
|
|
80
84
|
}
|
|
81
|
-
visitDeclareClassStmt(_stmt, _context) {
|
|
82
|
-
throw new Error('Method not implemented.');
|
|
83
|
-
}
|
|
84
85
|
visitIfStmt(stmt, context) {
|
|
85
86
|
return this.attachComments(this.factory.createIfStatement(stmt.condition.visitExpression(this, context), this.factory.createBlock(this.visitStatements(stmt.trueCase, context.withStatementMode)), stmt.falseCase.length > 0
|
|
86
87
|
? this.factory.createBlock(this.visitStatements(stmt.falseCase, context.withStatementMode))
|
|
@@ -109,13 +110,6 @@ class ExpressionTranslatorVisitor {
|
|
|
109
110
|
const target = this.factory.createPropertyAccess(expr.receiver.visitExpression(this, context), expr.name);
|
|
110
111
|
return this.factory.createAssignment(target, expr.value.visitExpression(this, context));
|
|
111
112
|
}
|
|
112
|
-
visitInvokeMethodExpr(ast, context) {
|
|
113
|
-
const target = ast.receiver.visitExpression(this, context);
|
|
114
|
-
return this.setSourceMapRange(this.factory.createCallExpression(ast.name !== null
|
|
115
|
-
? this.factory.createPropertyAccess(target, ast.name)
|
|
116
|
-
: target, ast.args.map((arg) => arg.visitExpression(this, context)),
|
|
117
|
-
/* pure */ false), ast.sourceSpan);
|
|
118
|
-
}
|
|
119
113
|
visitInvokeFunctionExpr(ast, context) {
|
|
120
114
|
return this.setSourceMapRange(this.factory.createCallExpression(ast.fn.visitExpression(this, context), ast.args.map((arg) => arg.visitExpression(this, context)), ast.pure), ast.sourceSpan);
|
|
121
115
|
}
|
|
@@ -182,12 +176,6 @@ class ExpressionTranslatorVisitor {
|
|
|
182
176
|
visitNotExpr(ast, context) {
|
|
183
177
|
return this.factory.createUnaryExpression('!', ast.condition.visitExpression(this, context));
|
|
184
178
|
}
|
|
185
|
-
visitAssertNotNullExpr(ast, context) {
|
|
186
|
-
return ast.condition.visitExpression(this, context);
|
|
187
|
-
}
|
|
188
|
-
visitCastExpr(ast, context) {
|
|
189
|
-
return ast.value.visitExpression(this, context);
|
|
190
|
-
}
|
|
191
179
|
visitFunctionExpr(ast, context) {
|
|
192
180
|
var _a;
|
|
193
181
|
return this.factory.createFunctionExpression((_a = ast.name) !== null && _a !== void 0 ? _a : null, ast.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(ast.statements, context)));
|
|
@@ -5,8 +5,8 @@
|
|
|
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
|
|
9
|
-
import { AstFactory, BinaryOperator, LeadingComment, ObjectLiteralProperty, SourceMapRange, TemplateLiteral, UnaryOperator, VariableDeclarationType } from
|
|
8
|
+
import ts from 'typescript';
|
|
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.
|
|
12
12
|
*/
|
|
@@ -20,10 +20,7 @@ export declare class TypeScriptAstFactory implements AstFactory<ts.Statement, ts
|
|
|
20
20
|
createBinaryExpression(leftOperand: ts.Expression, operator: BinaryOperator, rightOperand: ts.Expression): ts.Expression;
|
|
21
21
|
createBlock(body: ts.Statement[]): ts.Statement;
|
|
22
22
|
createCallExpression(callee: ts.Expression, args: ts.Expression[], pure: boolean): ts.Expression;
|
|
23
|
-
createConditional:
|
|
24
|
-
(condition: ts.Expression, whenTrue: ts.Expression, whenFalse: ts.Expression): ts.ConditionalExpression;
|
|
25
|
-
(condition: ts.Expression, questionToken: ts.QuestionToken, whenTrue: ts.Expression, colonToken: ts.ColonToken, whenFalse: ts.Expression): ts.ConditionalExpression;
|
|
26
|
-
};
|
|
23
|
+
createConditional(condition: ts.Expression, whenTrue: ts.Expression, whenFalse: ts.Expression): ts.Expression;
|
|
27
24
|
createElementAccess: (expression: ts.Expression, index: number | ts.Expression) => ts.ElementAccessExpression;
|
|
28
25
|
createExpressionStatement: (expression: ts.Expression) => ts.ExpressionStatement;
|
|
29
26
|
createFunctionDeclaration(functionName: string, parameters: string[], body: ts.Statement): ts.Statement;
|