static-injector 3.0.0 → 4.0.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 +65 -43
- package/import/es2022/di/index.js +1 -0
- package/import/es2022/di/initializer_token.js +1 -1
- package/import/es2022/di/inject_switch.js +1 -2
- package/import/es2022/di/injection_token.js +2 -0
- package/import/es2022/di/injector.js +3 -3
- package/import/es2022/di/injector_compatibility.js +23 -0
- package/import/es2022/di/injector_token.js +2 -3
- package/import/es2022/di/internal_tokens.js +1 -1
- package/import/es2022/di/r3_injector.js +15 -14
- package/import/es2022/di/scope.js +1 -1
- package/import/es2022/di.js +24 -0
- package/import/es2022/render3/errors_di.js +2 -2
- package/import/es2022/render3/instructions/di.js +7 -0
- package/import/es2022/util/array_utils.js +7 -0
- package/import/es2022/util/stringify.js +1 -1
- package/import/fesm2022/index.js +59 -37
- package/import/typings/di/create_injector.d.ts +2 -2
- package/import/typings/di/forward_ref.d.ts +1 -1
- package/import/typings/di/index.d.ts +1 -0
- package/import/typings/di/injector.d.ts +3 -3
- package/import/typings/di/injector_compatibility.d.ts +2 -1
- package/import/typings/di/injector_token.d.ts +1 -1
- package/import/typings/di/interface/provider.d.ts +12 -12
- package/import/typings/di/metadata.d.ts +2 -2
- package/import/typings/di/null_injector.d.ts +1 -1
- package/import/typings/di/r3_injector.d.ts +1 -1
- package/import/typings/di.d.ts +24 -0
- package/import/typings/errors.d.ts +4 -1
- package/import/typings/render3/errors_di.d.ts +2 -1
- package/import/typings/render3/instructions/di.d.ts +7 -0
- package/import/typings/util/array_utils.d.ts +7 -0
- package/import/typings/util/empty.d.ts +1 -1
- package/import/typings/util/stringify.d.ts +1 -1
- package/package.json +8 -6
- package/readme.md +33 -23
- package/transform/compiler/src/compiler.d.ts +0 -22
- package/transform/compiler/src/compiler.js +0 -26
- package/transform/compiler/src/core.d.ts +6 -0
- package/transform/compiler/src/core.js +13 -0
- package/transform/compiler/src/output/output_ast.d.ts +8 -6
- package/transform/compiler/src/output/output_ast.js +10 -6
- package/transform/compiler/src/render3/partial/api.d.ts +5 -0
- package/transform/compiler/src/render3/r3_identifiers.js +4 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -7
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -7
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +2 -3
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +4 -31
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +3 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +14 -2
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +5 -5
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -7
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -7
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -7
- package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -7
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -7
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -7
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +7 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +3 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +16 -5
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +4 -3
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +25 -9
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -7
- package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -7
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +35 -24
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -7
- package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -7
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +21 -3
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +13 -3
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +12 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +3 -1
- package/transform/injectable-transform.js +1 -1
|
@@ -20,8 +20,10 @@ const util_1 = require("./util");
|
|
|
20
20
|
*/
|
|
21
21
|
class TypeScriptReflectionHost {
|
|
22
22
|
checker;
|
|
23
|
-
|
|
23
|
+
isLocalCompilation;
|
|
24
|
+
constructor(checker, isLocalCompilation = false) {
|
|
24
25
|
this.checker = checker;
|
|
26
|
+
this.isLocalCompilation = isLocalCompilation;
|
|
25
27
|
}
|
|
26
28
|
getDecoratorsOfDeclaration(declaration) {
|
|
27
29
|
const decorators = typescript_1.default.canHaveDecorators(declaration)
|
|
@@ -70,7 +72,7 @@ class TypeScriptReflectionHost {
|
|
|
70
72
|
typeNode = childTypeNodes[0];
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
|
-
const typeValueReference = (0, type_to_value_1.typeToValue)(typeNode, this.checker);
|
|
75
|
+
const typeValueReference = (0, type_to_value_1.typeToValue)(typeNode, this.checker, this.isLocalCompilation);
|
|
74
76
|
return {
|
|
75
77
|
name,
|
|
76
78
|
nameNode: node.name,
|
|
@@ -280,6 +282,18 @@ class TypeScriptReflectionHost {
|
|
|
280
282
|
isStatic,
|
|
281
283
|
};
|
|
282
284
|
}
|
|
285
|
+
_viaModule(declaration, originalId, importInfo) {
|
|
286
|
+
if (importInfo === null &&
|
|
287
|
+
originalId !== null &&
|
|
288
|
+
declaration.getSourceFile() !== originalId.getSourceFile()) {
|
|
289
|
+
return host_1.AmbientImport;
|
|
290
|
+
}
|
|
291
|
+
return importInfo !== null &&
|
|
292
|
+
importInfo.from !== null &&
|
|
293
|
+
!importInfo.from.startsWith('.')
|
|
294
|
+
? importInfo.from
|
|
295
|
+
: null;
|
|
296
|
+
}
|
|
283
297
|
}
|
|
284
298
|
exports.TypeScriptReflectionHost = TypeScriptReflectionHost;
|
|
285
299
|
function reflectObjectLiteral(node) {
|
|
@@ -353,15 +367,17 @@ function getFarLeftIdentifier(propertyAccess) {
|
|
|
353
367
|
: null;
|
|
354
368
|
}
|
|
355
369
|
/**
|
|
356
|
-
*
|
|
357
|
-
* `NamespaceImport`. If not return `null`.
|
|
370
|
+
* Gets the closest ancestor `ImportDeclaration` to a node.
|
|
358
371
|
*/
|
|
359
372
|
function getContainingImportDeclaration(node) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
373
|
+
let parent = node.parent;
|
|
374
|
+
while (parent && !typescript_1.default.isSourceFile(parent)) {
|
|
375
|
+
if (typescript_1.default.isImportDeclaration(parent)) {
|
|
376
|
+
return parent;
|
|
377
|
+
}
|
|
378
|
+
parent = parent.parent;
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
365
381
|
}
|
|
366
382
|
exports.getContainingImportDeclaration = getContainingImportDeclaration;
|
|
367
383
|
/**
|
|
@@ -1,9 +1,2 @@
|
|
|
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
1
|
export * from './src/api';
|
|
9
2
|
export * from './src/utils';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
9
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
3
|
if (k2 === undefined) k2 = k;
|
|
11
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -12,4 +12,4 @@ import { ImportManager } from '../../translator';
|
|
|
12
12
|
* and before the module body.
|
|
13
13
|
* Can optionally add extra statements (e.g. new constants) before the body as well.
|
|
14
14
|
*/
|
|
15
|
-
export declare function addImports(importManager: ImportManager, sf: ts.SourceFile, extraStatements?: ts.Statement[]): ts.SourceFile;
|
|
15
|
+
export declare function addImports(factory: ts.NodeFactory | undefined, importManager: ImportManager, sf: ts.SourceFile, extraStatements?: ts.Statement[]): ts.SourceFile;
|
|
@@ -17,29 +17,13 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
17
17
|
* and before the module body.
|
|
18
18
|
* Can optionally add extra statements (e.g. new constants) before the body as well.
|
|
19
19
|
*/
|
|
20
|
-
function addImports(importManager, sf, extraStatements = []) {
|
|
20
|
+
function addImports(factory = typescript_1.default.factory, importManager, sf, extraStatements = []) {
|
|
21
21
|
// Generate the import statements to prepend.
|
|
22
|
-
const addedImports = importManager
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/* namedBindings */ typescript_1.default.factory.createNamespaceImport(qualifier));
|
|
28
|
-
const decl = typescript_1.default.factory.createImportDeclaration(
|
|
29
|
-
/* modifiers */ undefined,
|
|
30
|
-
/* importClause */ importClause,
|
|
31
|
-
/* moduleSpecifier */ typescript_1.default.factory.createStringLiteral(i.specifier));
|
|
32
|
-
// Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
|
|
33
|
-
// transforms such as tsickle to properly process references to this import.
|
|
34
|
-
//
|
|
35
|
-
// This operation is load-bearing in g3 as some imported modules contain special metadata
|
|
36
|
-
// generated by clutz, which tsickle uses to transform imports and references to those imports.
|
|
37
|
-
//
|
|
38
|
-
// TODO(alxhub): add a test for this when tsickle is updated externally to depend on this
|
|
39
|
-
// behavior.
|
|
40
|
-
typescript_1.default.setOriginalNode(i.qualifier, decl);
|
|
41
|
-
return decl;
|
|
42
|
-
});
|
|
22
|
+
const addedImports = importManager
|
|
23
|
+
.getAllImports(sf.fileName)
|
|
24
|
+
.map((i) => i.qualifier !== null
|
|
25
|
+
? createNamespaceImportDecl(i, factory)
|
|
26
|
+
: createSideEffectImportDecl(i, factory));
|
|
43
27
|
// Filter out the existing imports and the source file body. All new statements
|
|
44
28
|
// will be inserted between them.
|
|
45
29
|
const existingImports = sf.statements.filter((stmt) => isImportStatement(stmt));
|
|
@@ -49,8 +33,8 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
49
33
|
// If we prepend imports, we also prepend NotEmittedStatement to use it as an anchor
|
|
50
34
|
// for @fileoverview Closure annotation. If there is no @fileoverview annotations, this
|
|
51
35
|
// statement would be a noop.
|
|
52
|
-
const fileoverviewAnchorStmt =
|
|
53
|
-
return
|
|
36
|
+
const fileoverviewAnchorStmt = factory.createNotEmittedStatement(sf);
|
|
37
|
+
return factory.updateSourceFile(sf, factory.createNodeArray([
|
|
54
38
|
fileoverviewAnchorStmt,
|
|
55
39
|
...existingImports,
|
|
56
40
|
...addedImports,
|
|
@@ -61,6 +45,33 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
61
45
|
return sf;
|
|
62
46
|
}
|
|
63
47
|
exports.addImports = addImports;
|
|
48
|
+
function createNamespaceImportDecl(i, factory) {
|
|
49
|
+
const qualifier = factory.createIdentifier(i.qualifier.text);
|
|
50
|
+
const importClause = factory.createImportClause(
|
|
51
|
+
/* isTypeOnly */ false,
|
|
52
|
+
/* name */ undefined,
|
|
53
|
+
/* namedBindings */ factory.createNamespaceImport(qualifier));
|
|
54
|
+
const decl = factory.createImportDeclaration(
|
|
55
|
+
/* modifiers */ undefined,
|
|
56
|
+
/* importClause */ importClause,
|
|
57
|
+
/* moduleSpecifier */ factory.createStringLiteral(i.specifier));
|
|
58
|
+
// Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
|
|
59
|
+
// transforms such as tsickle to properly process references to this import.
|
|
60
|
+
//
|
|
61
|
+
// This operation is load-bearing in g3 as some imported modules contain special metadata
|
|
62
|
+
// generated by clutz, which tsickle uses to transform imports and references to those imports.
|
|
63
|
+
//
|
|
64
|
+
// TODO(alxhub): add a test for this when tsickle is updated externally to depend on this
|
|
65
|
+
// behavior.
|
|
66
|
+
typescript_1.default.setOriginalNode(i.qualifier, decl);
|
|
67
|
+
return decl;
|
|
68
|
+
}
|
|
69
|
+
function createSideEffectImportDecl(i, factory) {
|
|
70
|
+
return factory.createImportDeclaration(
|
|
71
|
+
/* modifiers */ undefined,
|
|
72
|
+
/* importClause */ undefined,
|
|
73
|
+
/* moduleSpecifier */ typescript_1.default.factory.createStringLiteral(i.specifier));
|
|
74
|
+
}
|
|
64
75
|
function isImportStatement(stmt) {
|
|
65
76
|
return (typescript_1.default.isImportDeclaration(stmt) ||
|
|
66
77
|
typescript_1.default.isImportEqualsDeclaration(stmt) ||
|
|
@@ -1,10 +1,3 @@
|
|
|
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
1
|
export * from './src/context';
|
|
9
2
|
export * from './src/translator';
|
|
10
3
|
export * from './src/typescript_ast_factory';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
9
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
3
|
if (k2 === undefined) k2 = k;
|
|
11
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -221,7 +221,7 @@ export type UnaryOperator = '+' | '-' | '!';
|
|
|
221
221
|
/**
|
|
222
222
|
* The binary operators supported by the `AstFactory`.
|
|
223
223
|
*/
|
|
224
|
-
export type BinaryOperator = '&&' | '>' | '>=' | '&' | '/' | '==' | '===' | '<' | '<=' | '-' | '%' | '*' | '!=' | '!==' | '||' | '+' | '??';
|
|
224
|
+
export type BinaryOperator = '&&' | '>' | '>=' | '&' | '|' | '/' | '==' | '===' | '<' | '<=' | '-' | '%' | '*' | '!=' | '!==' | '||' | '+' | '??';
|
|
225
225
|
/**
|
|
226
226
|
* The original location of the start or end of a node created by the `AstFactory`.
|
|
227
227
|
*/
|
|
@@ -9,21 +9,39 @@ import ts from 'typescript';
|
|
|
9
9
|
import { ImportRewriter } from '../../imports';
|
|
10
10
|
import { ImportGenerator, NamedImport } from './api/import_generator';
|
|
11
11
|
/**
|
|
12
|
-
* Information about
|
|
12
|
+
* Information about a namespace import that has been added to a module.
|
|
13
13
|
*/
|
|
14
|
-
export interface
|
|
14
|
+
export interface NamespaceImport {
|
|
15
15
|
/** The name of the module that has been imported. */
|
|
16
16
|
specifier: string;
|
|
17
17
|
/** The `ts.Identifier` by which the imported module is known. */
|
|
18
18
|
qualifier: ts.Identifier;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Information about a side effect import that has been added to a module.
|
|
22
|
+
*/
|
|
23
|
+
export interface SideEffectImport {
|
|
24
|
+
/** The name of the module that has been imported. */
|
|
25
|
+
specifier: string;
|
|
26
|
+
/**
|
|
27
|
+
* The qualifier of a side effect import is always non-existent, and that can be used to check
|
|
28
|
+
* whether the import is side effect or not.
|
|
29
|
+
*/
|
|
30
|
+
qualifier: null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Information about an import that has been added to a module.
|
|
34
|
+
*/
|
|
35
|
+
export type Import = NamespaceImport | SideEffectImport;
|
|
20
36
|
export declare class ImportManager implements ImportGenerator<ts.Identifier> {
|
|
21
37
|
protected rewriter: ImportRewriter;
|
|
22
38
|
private prefix;
|
|
39
|
+
private factory;
|
|
23
40
|
private specifierToIdentifier;
|
|
24
41
|
private nextIndex;
|
|
25
|
-
constructor(rewriter?: ImportRewriter, prefix?: string);
|
|
42
|
+
constructor(rewriter?: ImportRewriter, prefix?: string, factory?: ts.NodeFactory);
|
|
26
43
|
generateNamespaceImport(moduleName: string): ts.Identifier;
|
|
27
44
|
generateNamedImport(moduleName: string, originalSymbol: string): NamedImport<ts.Identifier>;
|
|
45
|
+
generateSideEffectImport(moduleName: string): void;
|
|
28
46
|
getAllImports(contextPath: string): Import[];
|
|
29
47
|
}
|
|
@@ -16,15 +16,20 @@ const imports_1 = require("../../imports");
|
|
|
16
16
|
class ImportManager {
|
|
17
17
|
rewriter;
|
|
18
18
|
prefix;
|
|
19
|
+
factory;
|
|
19
20
|
specifierToIdentifier = new Map();
|
|
20
21
|
nextIndex = 0;
|
|
21
|
-
constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i') {
|
|
22
|
+
constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i', factory = typescript_1.default.factory) {
|
|
22
23
|
this.rewriter = rewriter;
|
|
23
24
|
this.prefix = prefix;
|
|
25
|
+
this.factory = factory;
|
|
24
26
|
}
|
|
25
27
|
generateNamespaceImport(moduleName) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
// The case `specifierToIdentifier.get(moduleName) === null` is also considered to overwrite the
|
|
29
|
+
// side effect import since namedspace import is enough.
|
|
30
|
+
if (!this.specifierToIdentifier.has(moduleName) ||
|
|
31
|
+
this.specifierToIdentifier.get(moduleName) === null) {
|
|
32
|
+
this.specifierToIdentifier.set(moduleName, this.factory.createIdentifier(`${this.prefix}${this.nextIndex++}`));
|
|
28
33
|
}
|
|
29
34
|
return this.specifierToIdentifier.get(moduleName);
|
|
30
35
|
}
|
|
@@ -41,6 +46,11 @@ class ImportManager {
|
|
|
41
46
|
const moduleImport = this.generateNamespaceImport(moduleName);
|
|
42
47
|
return { moduleImport, symbol };
|
|
43
48
|
}
|
|
49
|
+
generateSideEffectImport(moduleName) {
|
|
50
|
+
if (!this.specifierToIdentifier.has(moduleName)) {
|
|
51
|
+
this.specifierToIdentifier.set(moduleName, null);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
44
54
|
getAllImports(contextPath) {
|
|
45
55
|
const imports = [];
|
|
46
56
|
for (const [originalSpecifier, qualifier] of this.specifierToIdentifier) {
|
|
@@ -41,6 +41,7 @@ const BINARY_OPERATORS = new Map([
|
|
|
41
41
|
[o.BinaryOperator.Bigger, '>'],
|
|
42
42
|
[o.BinaryOperator.BiggerEquals, '>='],
|
|
43
43
|
[o.BinaryOperator.BitwiseAnd, '&'],
|
|
44
|
+
[o.BinaryOperator.BitwiseOr, '|'],
|
|
44
45
|
[o.BinaryOperator.Divide, '/'],
|
|
45
46
|
[o.BinaryOperator.Equals, '=='],
|
|
46
47
|
[o.BinaryOperator.Identical, '==='],
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
import ts from 'typescript';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a TypeScript node representing a numeric value.
|
|
11
|
+
*/
|
|
12
|
+
export declare function tsNumericExpression(value: number): ts.NumericLiteral | ts.PrefixUnaryExpression;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.tsNumericExpression = void 0;
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
/**
|
|
16
|
+
* Creates a TypeScript node representing a numeric value.
|
|
17
|
+
*/
|
|
18
|
+
function tsNumericExpression(value) {
|
|
19
|
+
// As of TypeScript 5.3 negative numbers are represented as `prefixUnaryOperator` and passing a
|
|
20
|
+
// negative number (even as a string) into `createNumericLiteral` will result in an error.
|
|
21
|
+
if (value < 0) {
|
|
22
|
+
const operand = typescript_1.default.factory.createNumericLiteral(Math.abs(value));
|
|
23
|
+
return typescript_1.default.factory.createPrefixUnaryExpression(typescript_1.default.SyntaxKind.MinusToken, operand);
|
|
24
|
+
}
|
|
25
|
+
return typescript_1.default.factory.createNumericLiteral(value);
|
|
26
|
+
}
|
|
27
|
+
exports.tsNumericExpression = tsNumericExpression;
|
|
@@ -12,6 +12,7 @@ exports.attachComments = exports.createTemplateTail = exports.createTemplateMidd
|
|
|
12
12
|
* found in the LICENSE file at https://angular.io/license
|
|
13
13
|
*/
|
|
14
14
|
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
const ts_util_1 = require("./ts_util");
|
|
15
16
|
/**
|
|
16
17
|
* Different optimizers use different annotations on a function or method call to indicate its pure
|
|
17
18
|
* status.
|
|
@@ -36,6 +37,7 @@ const BINARY_OPERATORS = {
|
|
|
36
37
|
'>': typescript_1.default.SyntaxKind.GreaterThanToken,
|
|
37
38
|
'>=': typescript_1.default.SyntaxKind.GreaterThanEqualsToken,
|
|
38
39
|
'&': typescript_1.default.SyntaxKind.AmpersandToken,
|
|
40
|
+
'|': typescript_1.default.SyntaxKind.BarToken,
|
|
39
41
|
'/': typescript_1.default.SyntaxKind.SlashToken,
|
|
40
42
|
'==': typescript_1.default.SyntaxKind.EqualsEqualsToken,
|
|
41
43
|
'===': typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken,
|
|
@@ -127,7 +129,7 @@ class TypeScriptAstFactory {
|
|
|
127
129
|
return value ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse();
|
|
128
130
|
}
|
|
129
131
|
else if (typeof value === 'number') {
|
|
130
|
-
return
|
|
132
|
+
return (0, ts_util_1.tsNumericExpression)(value);
|
|
131
133
|
}
|
|
132
134
|
else {
|
|
133
135
|
return typescript_1.default.factory.createStringLiteral(value);
|
|
@@ -214,7 +214,7 @@ class InjectableTransformerFactory {
|
|
|
214
214
|
return nodeArrayFromDecoratorsArray(filtered);
|
|
215
215
|
}
|
|
216
216
|
updateStatements(node, importManager) {
|
|
217
|
-
return (0, transform_1.addImports)(importManager, node);
|
|
217
|
+
return (0, transform_1.addImports)(typescript_1.default.factory, importManager, node);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
exports.InjectableTransformerFactory = InjectableTransformerFactory;
|