static-injector 1.0.9 → 2.0.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.
Files changed (78) hide show
  1. package/import/commonjs/index.js +331 -118
  2. package/import/es2015/di/create_injector.js +30 -0
  3. package/import/es2015/di/initializer_token.js +15 -0
  4. package/import/es2015/di/inject_switch.js +27 -6
  5. package/import/es2015/{decorator → di}/injectable.js +0 -0
  6. package/import/es2015/di/injection_token.js +6 -0
  7. package/import/es2015/di/injector.js +6 -8
  8. package/import/es2015/di/injector_compatibility.js +90 -34
  9. package/import/es2015/di/injector_token.js +1 -1
  10. package/import/es2015/di/interface/defs.js +39 -0
  11. package/import/es2015/di/interface/injector.js +1 -0
  12. package/import/es2015/di/internal_tokens.js +9 -0
  13. package/import/es2015/di/metadata.js +4 -4
  14. package/import/es2015/di/provider_collection.js +49 -0
  15. package/import/es2015/di/r3_injector.js +96 -66
  16. package/import/es2015/di/scope.js +2 -2
  17. package/import/es2015/index.js +1 -1
  18. package/import/es2015/render3/errors_di.js +1 -1
  19. package/import/fesm2015/index.js +322 -108
  20. package/import/typings/di/create_injector.d.ts +23 -0
  21. package/import/typings/di/initializer_token.d.ts +15 -0
  22. package/import/typings/di/inject_switch.d.ts +7 -2
  23. package/import/typings/{decorator → di}/injectable.d.ts +1 -1
  24. package/import/typings/di/injection_token.d.ts +4 -0
  25. package/import/typings/di/injector.d.ts +20 -7
  26. package/import/typings/di/injector_compatibility.d.ts +42 -21
  27. package/import/typings/di/interface/defs.d.ts +10 -0
  28. package/import/typings/di/interface/injector.d.ts +26 -0
  29. package/import/typings/di/interface/provider.d.ts +1 -6
  30. package/import/typings/di/internal_tokens.d.ts +10 -0
  31. package/import/typings/di/provider_collection.d.ts +30 -0
  32. package/import/typings/di/r3_injector.d.ts +67 -36
  33. package/import/typings/di/scope.d.ts +3 -2
  34. package/import/typings/index.d.ts +1 -1
  35. package/package.json +4 -2
  36. package/transform/compiler/index.js +5 -1
  37. package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
  38. package/transform/compiler/src/injectable_compiler_2.js +20 -23
  39. package/transform/compiler/src/output/output_ast.d.ts +29 -108
  40. package/transform/compiler/src/output/output_ast.js +66 -188
  41. package/transform/compiler/src/render3/r3_factory.js +11 -7
  42. package/transform/compiler/src/render3/util.d.ts +64 -0
  43. package/transform/compiler/src/render3/util.js +52 -9
  44. package/transform/compiler/src/render3/view/util.js +5 -1
  45. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +5 -4
  46. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.js +32 -23
  47. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +1 -1
  48. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +33 -21
  49. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
  50. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +5 -1
  51. package/transform/compiler-cli/src/ngtsc/imports/index.js +5 -1
  52. package/transform/compiler-cli/src/ngtsc/reflection/index.js +5 -1
  53. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +1 -1
  54. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +6 -2
  55. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
  56. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +36 -23
  57. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +18 -13
  58. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +5 -1
  59. package/transform/compiler-cli/src/ngtsc/transform/index.js +5 -1
  60. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
  61. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +13 -8
  62. package/transform/compiler-cli/src/ngtsc/translator/index.js +5 -1
  63. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +3 -3
  64. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +7 -3
  65. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -4
  66. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +5 -17
  67. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
  68. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +67 -55
  69. package/{import/es2015/decorator/interface/provider.js → transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts} +1 -1
  70. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
  71. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +151 -0
  72. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +210 -0
  73. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +5 -1
  74. package/transform/index.js +5 -1
  75. package/transform/injectable-transform.js +33 -38
  76. package/import/typings/decorator/interface/provider.d.ts +0 -312
  77. package/transform/compiler/src/render3/partial/util.d.ts +0 -16
  78. package/transform/compiler/src/render3/partial/util.js +0 -44
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -36,15 +40,16 @@ const ts = __importStar(require("typescript"));
36
40
  function addImports(importManager, sf, extraStatements = []) {
37
41
  // Generate the import statements to prepend.
38
42
  const addedImports = importManager.getAllImports(sf.fileName).map((i) => {
39
- const qualifier = ts.createIdentifier(i.qualifier.text);
40
- const importClause = ts.createImportClause(
43
+ const qualifier = ts.factory.createIdentifier(i.qualifier.text);
44
+ const importClause = ts.factory.createImportClause(
45
+ /* isTypeOnly */ false,
41
46
  /* name */ undefined,
42
- /* namedBindings */ ts.createNamespaceImport(qualifier));
43
- const decl = ts.createImportDeclaration(
47
+ /* namedBindings */ ts.factory.createNamespaceImport(qualifier));
48
+ const decl = ts.factory.createImportDeclaration(
44
49
  /* decorators */ undefined,
45
50
  /* modifiers */ undefined,
46
51
  /* importClause */ importClause,
47
- /* moduleSpecifier */ ts.createLiteral(i.specifier));
52
+ /* moduleSpecifier */ ts.factory.createStringLiteral(i.specifier));
48
53
  // Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
49
54
  // transforms such as tsickle to properly process references to this import.
50
55
  //
@@ -65,8 +70,8 @@ function addImports(importManager, sf, extraStatements = []) {
65
70
  // If we prepend imports, we also prepend NotEmittedStatement to use it as an anchor
66
71
  // for @fileoverview Closure annotation. If there is no @fileoverview annotations, this
67
72
  // statement would be a noop.
68
- const fileoverviewAnchorStmt = ts.createNotEmittedStatement(sf);
69
- return ts.updateSourceFileNode(sf, ts.createNodeArray([
73
+ const fileoverviewAnchorStmt = ts.factory.createNotEmittedStatement(sf);
74
+ return ts.factory.updateSourceFile(sf, ts.factory.createNodeArray([
70
75
  fileoverviewAnchorStmt,
71
76
  ...existingImports,
72
77
  ...addedImports,
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -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 ts from "typescript";
9
- import { ImportRewriter } from "../../imports";
10
- import { ImportGenerator, NamedImport } from "./api/import_generator";
8
+ import * as 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
  */
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -30,7 +34,7 @@ exports.ImportManager = void 0;
30
34
  const ts = __importStar(require("typescript"));
31
35
  const imports_1 = require("../../imports");
32
36
  class ImportManager {
33
- constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = "i") {
37
+ constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i') {
34
38
  this.rewriter = rewriter;
35
39
  this.prefix = prefix;
36
40
  this.specifierToIdentifier = new Map();
@@ -38,7 +42,7 @@ class ImportManager {
38
42
  }
39
43
  generateNamespaceImport(moduleName) {
40
44
  if (!this.specifierToIdentifier.has(moduleName)) {
41
- this.specifierToIdentifier.set(moduleName, ts.createIdentifier(`${this.prefix}${this.nextIndex++}`));
45
+ this.specifierToIdentifier.set(moduleName, ts.factory.createIdentifier(`${this.prefix}${this.nextIndex++}`));
42
46
  }
43
47
  return this.specifierToIdentifier.get(moduleName);
44
48
  }
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -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 * as ts from "typescript";
9
- import { AstFactory, BinaryOperator, LeadingComment, ObjectLiteralProperty, SourceMapRange, TemplateLiteral, UnaryOperator, VariableDeclarationType } from "./api/ast_factory";
8
+ import * as 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;
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -43,28 +47,28 @@ var PureAnnotation;
43
47
  PureAnnotation["TERSER"] = "@__PURE__";
44
48
  })(PureAnnotation || (PureAnnotation = {}));
45
49
  const UNARY_OPERATORS = {
46
- "+": ts.SyntaxKind.PlusToken,
47
- "-": ts.SyntaxKind.MinusToken,
48
- "!": ts.SyntaxKind.ExclamationToken,
50
+ '+': ts.SyntaxKind.PlusToken,
51
+ '-': ts.SyntaxKind.MinusToken,
52
+ '!': ts.SyntaxKind.ExclamationToken,
49
53
  };
50
54
  const BINARY_OPERATORS = {
51
- "&&": ts.SyntaxKind.AmpersandAmpersandToken,
52
- ">": ts.SyntaxKind.GreaterThanToken,
53
- ">=": ts.SyntaxKind.GreaterThanEqualsToken,
54
- "&": ts.SyntaxKind.AmpersandToken,
55
- "/": ts.SyntaxKind.SlashToken,
56
- "==": ts.SyntaxKind.EqualsEqualsToken,
57
- "===": ts.SyntaxKind.EqualsEqualsEqualsToken,
58
- "<": ts.SyntaxKind.LessThanToken,
59
- "<=": ts.SyntaxKind.LessThanEqualsToken,
60
- "-": ts.SyntaxKind.MinusToken,
61
- "%": ts.SyntaxKind.PercentToken,
62
- "*": ts.SyntaxKind.AsteriskToken,
63
- "!=": ts.SyntaxKind.ExclamationEqualsToken,
64
- "!==": ts.SyntaxKind.ExclamationEqualsEqualsToken,
65
- "||": ts.SyntaxKind.BarBarToken,
66
- "+": ts.SyntaxKind.PlusToken,
67
- "??": ts.SyntaxKind.QuestionQuestionToken,
55
+ '&&': ts.SyntaxKind.AmpersandAmpersandToken,
56
+ '>': ts.SyntaxKind.GreaterThanToken,
57
+ '>=': ts.SyntaxKind.GreaterThanEqualsToken,
58
+ '&': ts.SyntaxKind.AmpersandToken,
59
+ '/': ts.SyntaxKind.SlashToken,
60
+ '==': ts.SyntaxKind.EqualsEqualsToken,
61
+ '===': ts.SyntaxKind.EqualsEqualsEqualsToken,
62
+ '<': ts.SyntaxKind.LessThanToken,
63
+ '<=': ts.SyntaxKind.LessThanEqualsToken,
64
+ '-': ts.SyntaxKind.MinusToken,
65
+ '%': ts.SyntaxKind.PercentToken,
66
+ '*': ts.SyntaxKind.AsteriskToken,
67
+ '!=': ts.SyntaxKind.ExclamationEqualsToken,
68
+ '!==': ts.SyntaxKind.ExclamationEqualsEqualsToken,
69
+ '||': ts.SyntaxKind.BarBarToken,
70
+ '+': ts.SyntaxKind.PlusToken,
71
+ '??': ts.SyntaxKind.QuestionQuestionToken,
68
72
  };
69
73
  const VAR_TYPES = {
70
74
  const: ts.NodeFlags.Const,
@@ -79,27 +83,26 @@ class TypeScriptAstFactory {
79
83
  this.annotateForClosureCompiler = annotateForClosureCompiler;
80
84
  this.externalSourceFiles = new Map();
81
85
  this.attachComments = attachComments;
82
- this.createArrayLiteral = ts.createArrayLiteral;
83
- this.createConditional = ts.createConditional;
84
- this.createElementAccess = ts.createElementAccess;
85
- this.createExpressionStatement = ts.createExpressionStatement;
86
- this.createIdentifier = ts.createIdentifier;
87
- this.createParenthesizedExpression = ts.createParen;
88
- this.createPropertyAccess = ts.createPropertyAccess;
89
- this.createThrowStatement = ts.createThrow;
90
- this.createTypeOfExpression = ts.createTypeOf;
86
+ this.createArrayLiteral = ts.factory.createArrayLiteralExpression;
87
+ this.createElementAccess = ts.factory.createElementAccessExpression;
88
+ this.createExpressionStatement = ts.factory.createExpressionStatement;
89
+ this.createIdentifier = ts.factory.createIdentifier;
90
+ this.createParenthesizedExpression = ts.factory.createParenthesizedExpression;
91
+ this.createPropertyAccess = ts.factory.createPropertyAccessExpression;
92
+ this.createThrowStatement = ts.factory.createThrowStatement;
93
+ this.createTypeOfExpression = ts.factory.createTypeOfExpression;
91
94
  }
92
95
  createAssignment(target, value) {
93
- return ts.createBinary(target, ts.SyntaxKind.EqualsToken, value);
96
+ return ts.factory.createBinaryExpression(target, ts.SyntaxKind.EqualsToken, value);
94
97
  }
95
98
  createBinaryExpression(leftOperand, operator, rightOperand) {
96
- return ts.createBinary(leftOperand, BINARY_OPERATORS[operator], rightOperand);
99
+ return ts.factory.createBinaryExpression(leftOperand, BINARY_OPERATORS[operator], rightOperand);
97
100
  }
98
101
  createBlock(body) {
99
- return ts.createBlock(body);
102
+ return ts.factory.createBlock(body);
100
103
  }
101
104
  createCallExpression(callee, args, pure) {
102
- const call = ts.createCall(callee, undefined, args);
105
+ const call = ts.factory.createCallExpression(callee, undefined, args);
103
106
  if (pure) {
104
107
  ts.addSyntheticLeadingComment(call, ts.SyntaxKind.MultiLineCommentTrivia, this.annotateForClosureCompiler
105
108
  ? PureAnnotation.CLOSURE
@@ -108,49 +111,58 @@ class TypeScriptAstFactory {
108
111
  }
109
112
  return call;
110
113
  }
114
+ createConditional(condition, whenTrue, whenFalse) {
115
+ return ts.factory.createConditionalExpression(condition, undefined, whenTrue, undefined, whenFalse);
116
+ }
111
117
  createFunctionDeclaration(functionName, parameters, body) {
112
118
  if (!ts.isBlock(body)) {
113
119
  throw new Error(`Invalid syntax, expected a block, but got ${ts.SyntaxKind[body.kind]}.`);
114
120
  }
115
- return ts.createFunctionDeclaration(undefined, undefined, undefined, functionName, undefined, parameters.map((param) => ts.createParameter(undefined, undefined, undefined, param)), undefined, body);
121
+ return ts.factory.createFunctionDeclaration(undefined, undefined, undefined, functionName, undefined, parameters.map((param) => ts.factory.createParameterDeclaration(undefined, undefined, undefined, param)), undefined, body);
116
122
  }
117
123
  createFunctionExpression(functionName, parameters, body) {
118
124
  if (!ts.isBlock(body)) {
119
125
  throw new Error(`Invalid syntax, expected a block, but got ${ts.SyntaxKind[body.kind]}.`);
120
126
  }
121
- return ts.createFunctionExpression(undefined, undefined, functionName !== null && functionName !== void 0 ? functionName : undefined, undefined, parameters.map((param) => ts.createParameter(undefined, undefined, undefined, param)), undefined, body);
127
+ return ts.factory.createFunctionExpression(undefined, undefined, functionName !== null && functionName !== void 0 ? functionName : undefined, undefined, parameters.map((param) => ts.factory.createParameterDeclaration(undefined, undefined, undefined, param)), undefined, body);
122
128
  }
123
129
  createIfStatement(condition, thenStatement, elseStatement) {
124
- return ts.createIf(condition, thenStatement, elseStatement !== null && elseStatement !== void 0 ? elseStatement : undefined);
130
+ return ts.factory.createIfStatement(condition, thenStatement, elseStatement !== null && elseStatement !== void 0 ? elseStatement : undefined);
125
131
  }
126
132
  createLiteral(value) {
127
133
  if (value === undefined) {
128
- return ts.createIdentifier("undefined");
134
+ return ts.factory.createIdentifier('undefined');
129
135
  }
130
136
  else if (value === null) {
131
- return ts.createNull();
137
+ return ts.factory.createNull();
138
+ }
139
+ else if (typeof value === 'boolean') {
140
+ return value ? ts.factory.createTrue() : ts.factory.createFalse();
141
+ }
142
+ else if (typeof value === 'number') {
143
+ return ts.factory.createNumericLiteral(value);
132
144
  }
133
145
  else {
134
- return ts.createLiteral(value);
146
+ return ts.factory.createStringLiteral(value);
135
147
  }
136
148
  }
137
149
  createNewExpression(expression, args) {
138
- return ts.createNew(expression, undefined, args);
150
+ return ts.factory.createNewExpression(expression, undefined, args);
139
151
  }
140
152
  createObjectLiteral(properties) {
141
- return ts.createObjectLiteral(properties.map((prop) => ts.createPropertyAssignment(prop.quoted
142
- ? ts.createLiteral(prop.propertyName)
143
- : ts.createIdentifier(prop.propertyName), prop.value)));
153
+ return ts.factory.createObjectLiteralExpression(properties.map((prop) => ts.factory.createPropertyAssignment(prop.quoted
154
+ ? ts.factory.createStringLiteral(prop.propertyName)
155
+ : ts.factory.createIdentifier(prop.propertyName), prop.value)));
144
156
  }
145
157
  createReturnStatement(expression) {
146
- return ts.createReturn(expression !== null && expression !== void 0 ? expression : undefined);
158
+ return ts.factory.createReturnStatement(expression !== null && expression !== void 0 ? expression : undefined);
147
159
  }
148
160
  createTaggedTemplate(tag, template) {
149
161
  let templateLiteral;
150
162
  const length = template.elements.length;
151
163
  const head = template.elements[0];
152
164
  if (length === 1) {
153
- templateLiteral = ts.createNoSubstitutionTemplateLiteral(head.cooked, head.raw);
165
+ templateLiteral = ts.factory.createNoSubstitutionTemplateLiteral(head.cooked, head.raw);
154
166
  }
155
167
  else {
156
168
  const spans = [];
@@ -161,7 +173,7 @@ class TypeScriptAstFactory {
161
173
  if (range !== null) {
162
174
  this.setSourceMapRange(middle, range);
163
175
  }
164
- spans.push(ts.createTemplateSpan(template.expressions[i - 1], middle));
176
+ spans.push(ts.factory.createTemplateSpan(template.expressions[i - 1], middle));
165
177
  }
166
178
  // Create the tail part
167
179
  const resolvedExpression = template.expressions[length - 2];
@@ -170,21 +182,21 @@ class TypeScriptAstFactory {
170
182
  if (templatePart.range !== null) {
171
183
  this.setSourceMapRange(templateTail, templatePart.range);
172
184
  }
173
- spans.push(ts.createTemplateSpan(resolvedExpression, templateTail));
185
+ spans.push(ts.factory.createTemplateSpan(resolvedExpression, templateTail));
174
186
  // Put it all together
175
- templateLiteral = ts.createTemplateExpression(ts.createTemplateHead(head.cooked, head.raw), spans);
187
+ templateLiteral = ts.factory.createTemplateExpression(ts.factory.createTemplateHead(head.cooked, head.raw), spans);
176
188
  }
177
189
  if (head.range !== null) {
178
190
  this.setSourceMapRange(templateLiteral, head.range);
179
191
  }
180
- return ts.createTaggedTemplate(tag, templateLiteral);
192
+ return ts.factory.createTaggedTemplateExpression(tag, undefined, templateLiteral);
181
193
  }
182
194
  createUnaryExpression(operator, operand) {
183
- return ts.createPrefix(UNARY_OPERATORS[operator], operand);
195
+ return ts.factory.createPrefixUnaryExpression(UNARY_OPERATORS[operator], operand);
184
196
  }
185
197
  createVariableDeclaration(variableName, initializer, type) {
186
- return ts.createVariableStatement(undefined, ts.createVariableDeclarationList([
187
- ts.createVariableDeclaration(variableName, undefined, initializer !== null && initializer !== void 0 ? initializer : undefined),
198
+ return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
199
+ ts.factory.createVariableDeclaration(variableName, undefined, undefined, initializer !== null && initializer !== void 0 ? initializer : undefined),
188
200
  ], VAR_TYPES[type]));
189
201
  }
190
202
  setSourceMapRange(node, sourceMapRange) {
@@ -216,7 +228,7 @@ exports.createTemplateMiddle = createTemplateMiddle;
216
228
  // HACK: Use this in place of `ts.createTemplateTail()`.
217
229
  // Revert once https://github.com/microsoft/TypeScript/issues/35374 is fixed.
218
230
  function createTemplateTail(cooked, raw) {
219
- const node = ts.createTemplateHead(cooked, raw);
231
+ const node = ts.factory.createTemplateHead(cooked, raw);
220
232
  node.kind = ts.SyntaxKind.TemplateTail;
221
233
  return node;
222
234
  }
@@ -236,7 +248,7 @@ function attachComments(statement, leadingComments) {
236
248
  ts.addSyntheticLeadingComment(statement, commentKind, comment.toString(), comment.trailingNewline);
237
249
  }
238
250
  else {
239
- for (const line of comment.toString().split("\n")) {
251
+ for (const line of comment.toString().split('\n')) {
240
252
  ts.addSyntheticLeadingComment(statement, commentKind, line, comment.trailingNewline);
241
253
  }
242
254
  }
@@ -5,4 +5,4 @@
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
- export {};
8
+ export * from './src/ts_cross_version_utils';
@@ -0,0 +1,24 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
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);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("./src/ts_cross_version_utils"), exports);
@@ -0,0 +1,151 @@
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
+ /** Equivalent of `ts.ModifierLike` which is only present in TS 4.8+. */
10
+ export declare type ModifierLike = ts.Modifier | ts.Decorator;
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;
13
+ /**
14
+ * Updates a `ts.ParameterDeclaration` declaration.
15
+ *
16
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
17
+ * We should remove it once we have dropped support for the older versions.
18
+ */
19
+ export declare const updateParameterDeclaration: Ts48UpdateParameterDeclarationFn;
20
+ /** Type of `ts.factory.updateImportDeclaration` in TS 4.8+. */
21
+ declare type Ts48UpdateImportDeclarationFn = (node: ts.ImportDeclaration, modifiers: readonly ts.Modifier[] | undefined, importClause: ts.ImportClause | undefined, moduleSpecifier: ts.Expression, assertClause: ts.AssertClause | undefined) => ts.ImportDeclaration;
22
+ /**
23
+ * Updates a `ts.ImportDeclaration` declaration.
24
+ *
25
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
26
+ * We should remove it once we have dropped support for the older versions.
27
+ */
28
+ export declare const updateImportDeclaration: Ts48UpdateImportDeclarationFn;
29
+ /** Type of `ts.factory.updateClassDeclaration` in TS 4.8+. */
30
+ declare type Ts48UpdateClassDeclarationFn = (node: ts.ClassDeclaration, modifiers: readonly ModifierLike[] | undefined, name: ts.Identifier | undefined, typeParameters: readonly ts.TypeParameterDeclaration[] | undefined, heritageClauses: readonly ts.HeritageClause[] | undefined, members: readonly ts.ClassElement[]) => ts.ClassDeclaration;
31
+ /**
32
+ * Updates a `ts.ClassDeclaration` declaration.
33
+ *
34
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
35
+ * We should remove it once we have dropped support for the older versions.
36
+ */
37
+ export declare const updateClassDeclaration: Ts48UpdateClassDeclarationFn;
38
+ /** Type of `ts.factory.createClassDeclaration` in TS 4.8+. */
39
+ declare type Ts48CreateClassDeclarationFn = (modifiers: readonly ModifierLike[] | undefined, name: ts.Identifier | undefined, typeParameters: readonly ts.TypeParameterDeclaration[] | undefined, heritageClauses: readonly ts.HeritageClause[] | undefined, members: readonly ts.ClassElement[]) => ts.ClassDeclaration;
40
+ /**
41
+ * Creates a `ts.ClassDeclaration` declaration.
42
+ *
43
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
44
+ * We should remove it once we have dropped support for the older versions.
45
+ */
46
+ export declare const createClassDeclaration: Ts48CreateClassDeclarationFn;
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;
151
+ export {};