static-injector 1.0.8
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 +1248 -0
- package/import/es2015/decorator/injectable.js +14 -0
- package/import/es2015/decorator/interface/provider.js +8 -0
- package/import/es2015/di/forward_ref.js +53 -0
- package/import/es2015/di/inject_switch.js +31 -0
- package/import/es2015/di/injection_token.js +71 -0
- package/import/es2015/di/injector.js +63 -0
- package/import/es2015/di/injector_compatibility.js +172 -0
- package/import/es2015/di/injector_marker.js +8 -0
- package/import/es2015/di/injector_token.js +21 -0
- package/import/es2015/di/interface/defs.js +72 -0
- package/import/es2015/di/interface/injector.js +25 -0
- package/import/es2015/di/interface/provider.js +8 -0
- package/import/es2015/di/metadata.js +49 -0
- package/import/es2015/di/null_injector.js +19 -0
- package/import/es2015/di/provider_token.js +8 -0
- package/import/es2015/di/r3_injector.js +382 -0
- package/import/es2015/di/scope.js +14 -0
- package/import/es2015/index.js +11 -0
- package/import/es2015/interface/lifecycle_hooks.js +8 -0
- package/import/es2015/interface/type.js +8 -0
- package/import/es2015/render3/definition_factory.js +15 -0
- package/import/es2015/render3/error_code.js +29 -0
- package/import/es2015/render3/errors_di.js +14 -0
- package/import/es2015/render3/fields.js +11 -0
- package/import/es2015/render3/instructions/di.js +23 -0
- package/import/es2015/render3/util/stringify_utils.js +37 -0
- package/import/es2015/util/array_utils.js +17 -0
- package/import/es2015/util/closure.js +19 -0
- package/import/es2015/util/decorators.js +30 -0
- package/import/es2015/util/empty.js +14 -0
- package/import/es2015/util/property.js +15 -0
- package/import/es2015/util/stringify.js +30 -0
- package/import/fesm2015/index.js +1211 -0
- package/import/typings/decorator/injectable.d.ts +82 -0
- package/import/typings/decorator/interface/provider.d.ts +312 -0
- package/import/typings/di/forward_ref.d.ts +49 -0
- package/import/typings/di/inject_switch.d.ts +17 -0
- package/import/typings/di/injection_token.d.ts +57 -0
- package/import/typings/di/injector.d.ts +76 -0
- package/import/typings/di/injector_compatibility.d.ts +77 -0
- package/import/typings/di/injector_marker.d.ts +23 -0
- package/import/typings/di/injector_token.d.ts +18 -0
- package/import/typings/di/interface/defs.d.ts +155 -0
- package/import/typings/di/interface/injector.d.ts +48 -0
- package/import/typings/di/interface/provider.d.ts +312 -0
- package/import/typings/di/metadata.d.ts +176 -0
- package/import/typings/di/null_injector.d.ts +11 -0
- package/import/typings/di/provider_token.d.ts +17 -0
- package/import/typings/di/r3_injector.d.ts +92 -0
- package/import/typings/di/scope.d.ts +14 -0
- package/import/typings/index.d.ts +11 -0
- package/import/typings/interface/lifecycle_hooks.d.ts +28 -0
- package/import/typings/interface/type.d.ts +21 -0
- package/import/typings/render3/definition_factory.d.ts +24 -0
- package/import/typings/render3/error_code.d.ts +24 -0
- package/import/typings/render3/errors_di.d.ts +2 -0
- package/import/typings/render3/fields.d.ts +8 -0
- package/import/typings/render3/instructions/di.d.ts +20 -0
- package/import/typings/render3/util/stringify_utils.d.ts +20 -0
- package/import/typings/util/array_utils.d.ts +10 -0
- package/import/typings/util/closure.d.ts +17 -0
- package/import/typings/util/decorators.d.ts +27 -0
- package/import/typings/util/empty.d.ts +14 -0
- package/import/typings/util/property.d.ts +8 -0
- package/import/typings/util/stringify.d.ts +8 -0
- package/package.json +34 -0
- package/readme.md +27 -0
- package/transform/compiler/index.d.ts +5 -0
- package/transform/compiler/index.js +17 -0
- package/transform/compiler/src/core.d.ts +19 -0
- package/transform/compiler/src/core.js +9 -0
- package/transform/compiler/src/injectable_compiler_2.d.ts +53 -0
- package/transform/compiler/src/injectable_compiler_2.js +159 -0
- package/transform/compiler/src/output/output_ast.d.ts +534 -0
- package/transform/compiler/src/output/output_ast.js +986 -0
- package/transform/compiler/src/parse_util.d.ts +50 -0
- package/transform/compiler/src/parse_util.js +61 -0
- package/transform/compiler/src/render3/partial/api.d.ts +166 -0
- package/transform/compiler/src/render3/partial/api.js +11 -0
- package/transform/compiler/src/render3/partial/util.d.ts +16 -0
- package/transform/compiler/src/render3/partial/util.js +44 -0
- package/transform/compiler/src/render3/r3_factory.d.ts +97 -0
- package/transform/compiler/src/render3/r3_factory.js +239 -0
- package/transform/compiler/src/render3/r3_identifiers.d.ts +20 -0
- package/transform/compiler/src/render3/r3_identifiers.js +51 -0
- package/transform/compiler/src/render3/util.d.ts +21 -0
- package/transform/compiler/src/render3/util.js +41 -0
- package/transform/compiler/src/render3/view/util.d.ts +30 -0
- package/transform/compiler/src/render3/view/util.js +57 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.d.ts +11 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +21 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +42 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +278 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.d.ts +91 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +370 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +24 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +76 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +188 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +206 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +2 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +14 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +1 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +13 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +36 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/core.js +25 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +3 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +15 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +667 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +98 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +24 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +271 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +50 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +396 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +12 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +45 -0
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +2 -0
- package/transform/compiler-cli/src/ngtsc/transform/index.js +14 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +115 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +30 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +15 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +84 -0
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +5 -0
- package/transform/compiler-cli/src/ngtsc/translator/index.js +17 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +274 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js +9 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +9 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +18 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +29 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +70 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +58 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +270 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +54 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +245 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +13 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +21 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +11 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +39 -0
- package/transform/index.d.ts +1 -0
- package/transform/index.js +13 -0
- package/transform/injectable-transform.d.ts +41 -0
- package/transform/injectable-transform.js +195 -0
- package/transform/node-Iteration.d.ts +2 -0
- package/transform/node-Iteration.js +12 -0
package/readme.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# 简介
|
|
2
|
+
|
|
3
|
+
- 这是 Angualr 依赖注入的独立版本,初始版本逻辑为从 Angular 源码中提取出来,并修复了一些已知 bug
|
|
4
|
+
- 使用方法与 Angular 的依赖注入完全一致
|
|
5
|
+
|
|
6
|
+
# 使用方法
|
|
7
|
+
|
|
8
|
+
- 以`Injector.create`创建第一级依赖注入器
|
|
9
|
+
- 声明为依赖注入类即为`@Injectable`装饰器
|
|
10
|
+
|
|
11
|
+
# 与`injection-js`的不同
|
|
12
|
+
|
|
13
|
+
- `injection-js`属于动态依赖注入,是 Angular5 之前使用的版本,Angular5 之后转为静态依赖注入
|
|
14
|
+
- 理论上会比`injection-js`快一些(否则 Angular 也不会做替换...),但是没有做 Benchmark
|
|
15
|
+
- 需要会使用`typescript`调用转换器进行转换,或者使用 webpack 的 ts-loader 传入转换器,或者其他转换工具支持 typescript 并且支持 typescript 的自定义转换器
|
|
16
|
+
> 未来会提供各个打包工具的使用方法
|
|
17
|
+
- 两者基本上可以互换(细节部分需要调整)
|
|
18
|
+
|
|
19
|
+
# 测试
|
|
20
|
+
|
|
21
|
+
- 做了一部分的单元测试.保证大部分功能正常使用
|
|
22
|
+
- 因为大部分代码本身就是从 Angular 中提取的,所以稳定性肯定也是有保证
|
|
23
|
+
|
|
24
|
+
# 模板
|
|
25
|
+
|
|
26
|
+
- [webpack 下使用](https://github.com/wszgrcy/static-injector-webpack-template)
|
|
27
|
+
- [rollup 下使用](https://github.com/wszgrcy/static-injector-rollup-template)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./src/injectable_compiler_2"), exports);
|
|
14
|
+
__exportStar(require("./src/render3/r3_factory"), exports);
|
|
15
|
+
__exportStar(require("./src/output/output_ast"), exports);
|
|
16
|
+
__exportStar(require("./src/render3/util"), exports);
|
|
17
|
+
__exportStar(require("./src/parse_util"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Injection flags for DI.
|
|
10
|
+
*/
|
|
11
|
+
export declare const enum InjectFlags {
|
|
12
|
+
Default = 0,
|
|
13
|
+
/** Don't descend into ancestors of the node requesting injection. */
|
|
14
|
+
Self = 2,
|
|
15
|
+
/** Skip the node that is requesting injection. */
|
|
16
|
+
SkipSelf = 4,
|
|
17
|
+
/** Inject `defaultValue` instead if token not found. */
|
|
18
|
+
Optional = 8
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,53 @@
|
|
|
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 * as o from "./output/output_ast";
|
|
9
|
+
import { R3DependencyMetadata } from "./render3/r3_factory";
|
|
10
|
+
import { R3CompiledExpression, R3Reference } from "./render3/util";
|
|
11
|
+
export interface R3InjectableMetadata {
|
|
12
|
+
name: string;
|
|
13
|
+
type: R3Reference;
|
|
14
|
+
internalType: o.Expression;
|
|
15
|
+
typeArgumentCount: number;
|
|
16
|
+
providedIn: R3ProviderExpression;
|
|
17
|
+
useClass?: R3ProviderExpression;
|
|
18
|
+
useFactory?: o.Expression;
|
|
19
|
+
useExisting?: R3ProviderExpression;
|
|
20
|
+
useValue?: R3ProviderExpression;
|
|
21
|
+
deps?: R3DependencyMetadata[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* An expression used when instantiating an injectable.
|
|
25
|
+
*
|
|
26
|
+
* This is the type of the `useClass`, `useExisting` and `useValue` properties of
|
|
27
|
+
* `R3InjectableMetadata` since those can refer to types that may eagerly reference types that have
|
|
28
|
+
* not yet been defined.
|
|
29
|
+
*/
|
|
30
|
+
export interface R3ProviderExpression<T extends o.Expression = o.Expression> {
|
|
31
|
+
/**
|
|
32
|
+
* The expression that is used to instantiate the Injectable.
|
|
33
|
+
*/
|
|
34
|
+
expression: T;
|
|
35
|
+
/**
|
|
36
|
+
* If true, then the `expression` contains a reference to something that has not yet been
|
|
37
|
+
* defined.
|
|
38
|
+
*
|
|
39
|
+
* This means that the expression must not be eagerly evaluated. Instead it must be wrapped in a
|
|
40
|
+
* function closure that will be evaluated lazily to allow the definition of the expression to be
|
|
41
|
+
* evaluated first.
|
|
42
|
+
*
|
|
43
|
+
* In some cases the expression will naturally be placed inside such a function closure, such as
|
|
44
|
+
* in a fully compiled factory function. In those case nothing more needs to be done.
|
|
45
|
+
*
|
|
46
|
+
* But in other cases, such as partial-compilation the expression will be located in top level
|
|
47
|
+
* code so will need to be wrapped in a function that is passed to a `forwardRef()` call.
|
|
48
|
+
*/
|
|
49
|
+
isForwardRef: boolean;
|
|
50
|
+
}
|
|
51
|
+
export declare function createR3ProviderExpression<T extends o.Expression>(expression: T, isForwardRef: boolean): R3ProviderExpression<T>;
|
|
52
|
+
export declare function compileInjectable(meta: R3InjectableMetadata, resolveForwardRefs: boolean): R3CompiledExpression;
|
|
53
|
+
export declare function createInjectableType(meta: R3InjectableMetadata): o.ExpressionType;
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.createInjectableType = exports.compileInjectable = exports.createR3ProviderExpression = void 0;
|
|
30
|
+
const o = __importStar(require("./output/output_ast"));
|
|
31
|
+
const util_1 = require("./render3/partial/util");
|
|
32
|
+
const r3_factory_1 = require("./render3/r3_factory");
|
|
33
|
+
const r3_identifiers_1 = require("./render3/r3_identifiers");
|
|
34
|
+
const util_2 = require("./render3/util");
|
|
35
|
+
const util_3 = require("./render3/view/util");
|
|
36
|
+
function createR3ProviderExpression(expression, isForwardRef) {
|
|
37
|
+
return { expression, isForwardRef };
|
|
38
|
+
}
|
|
39
|
+
exports.createR3ProviderExpression = createR3ProviderExpression;
|
|
40
|
+
function compileInjectable(meta, resolveForwardRefs) {
|
|
41
|
+
let result = null;
|
|
42
|
+
const factoryMeta = {
|
|
43
|
+
name: meta.name,
|
|
44
|
+
type: meta.type,
|
|
45
|
+
internalType: meta.internalType,
|
|
46
|
+
typeArgumentCount: meta.typeArgumentCount,
|
|
47
|
+
deps: [],
|
|
48
|
+
target: r3_factory_1.FactoryTarget.Injectable,
|
|
49
|
+
};
|
|
50
|
+
if (meta.useClass !== undefined) {
|
|
51
|
+
// meta.useClass has two modes of operation. Either deps are specified, in which case `new` is
|
|
52
|
+
// used to instantiate the class with dependencies injected, or deps are not specified and
|
|
53
|
+
// the factory of the class is used to instantiate it.
|
|
54
|
+
//
|
|
55
|
+
// A special case exists for useClass: Type where Type is the injectable type itself and no
|
|
56
|
+
// deps are specified, in which case 'useClass' is effectively ignored.
|
|
57
|
+
const useClassOnSelf = meta.useClass.expression.isEquivalent(meta.internalType);
|
|
58
|
+
let deps = undefined;
|
|
59
|
+
if (meta.deps !== undefined) {
|
|
60
|
+
deps = meta.deps;
|
|
61
|
+
}
|
|
62
|
+
if (deps !== undefined) {
|
|
63
|
+
// factory: () => new meta.useClass(...deps)
|
|
64
|
+
result = r3_factory_1.compileFactoryFunction(Object.assign(Object.assign({}, factoryMeta), { delegate: meta.useClass.expression, delegateDeps: deps, delegateType: r3_factory_1.R3FactoryDelegateType.Class }));
|
|
65
|
+
}
|
|
66
|
+
else if (useClassOnSelf) {
|
|
67
|
+
result = r3_factory_1.compileFactoryFunction(factoryMeta);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
result = {
|
|
71
|
+
statements: [],
|
|
72
|
+
expression: delegateToFactory(meta.type.value, meta.useClass.expression, resolveForwardRefs),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (meta.useFactory !== undefined) {
|
|
77
|
+
if (meta.deps !== undefined) {
|
|
78
|
+
result = r3_factory_1.compileFactoryFunction(Object.assign(Object.assign({}, factoryMeta), { delegate: meta.useFactory, delegateDeps: meta.deps || [], delegateType: r3_factory_1.R3FactoryDelegateType.Function }));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
result = {
|
|
82
|
+
statements: [],
|
|
83
|
+
expression: o.fn([], [new o.ReturnStatement(meta.useFactory.callFn([]))]),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (meta.useValue !== undefined) {
|
|
88
|
+
// Note: it's safe to use `meta.useValue` instead of the `USE_VALUE in meta` check used for
|
|
89
|
+
// client code because meta.useValue is an Expression which will be defined even if the actual
|
|
90
|
+
// value is undefined.
|
|
91
|
+
result = r3_factory_1.compileFactoryFunction(Object.assign(Object.assign({}, factoryMeta), { expression: meta.useValue.expression }));
|
|
92
|
+
}
|
|
93
|
+
else if (meta.useExisting !== undefined) {
|
|
94
|
+
// useExisting is an `inject` call on the existing token.
|
|
95
|
+
result = r3_factory_1.compileFactoryFunction(Object.assign(Object.assign({}, factoryMeta), { expression: o
|
|
96
|
+
.importExpr(r3_identifiers_1.Identifiers.inject)
|
|
97
|
+
.callFn([meta.useExisting.expression]) }));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
result = {
|
|
101
|
+
statements: [],
|
|
102
|
+
expression: delegateToFactory(meta.type.value, meta.internalType, resolveForwardRefs),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const token = meta.internalType;
|
|
106
|
+
const injectableProps = new util_3.DefinitionMap();
|
|
107
|
+
injectableProps.set("token", token);
|
|
108
|
+
injectableProps.set("factory", result.expression);
|
|
109
|
+
// Only generate providedIn property if it has a non-null value
|
|
110
|
+
if (meta.providedIn.expression.value !== null) {
|
|
111
|
+
injectableProps.set("providedIn", meta.providedIn.isForwardRef
|
|
112
|
+
? util_1.generateForwardRef(meta.providedIn.expression)
|
|
113
|
+
: meta.providedIn.expression);
|
|
114
|
+
}
|
|
115
|
+
const expression = o
|
|
116
|
+
.importExpr(r3_identifiers_1.Identifiers.ɵɵdefineInjectable)
|
|
117
|
+
.callFn([injectableProps.toLiteralMap()], undefined, true);
|
|
118
|
+
return {
|
|
119
|
+
expression,
|
|
120
|
+
type: createInjectableType(meta),
|
|
121
|
+
statements: result.statements,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
exports.compileInjectable = compileInjectable;
|
|
125
|
+
function createInjectableType(meta) {
|
|
126
|
+
return new o.ExpressionType(o.importExpr(r3_identifiers_1.Identifiers.InjectableDeclaration, [
|
|
127
|
+
util_2.typeWithParameters(meta.type.type, meta.typeArgumentCount),
|
|
128
|
+
]));
|
|
129
|
+
}
|
|
130
|
+
exports.createInjectableType = createInjectableType;
|
|
131
|
+
function delegateToFactory(type, internalType, unwrapForwardRefs) {
|
|
132
|
+
if (type.node === internalType.node) {
|
|
133
|
+
// The types are the same, so we can simply delegate directly to the type's factory.
|
|
134
|
+
// ```
|
|
135
|
+
// factory: type.ɵfac
|
|
136
|
+
// ```
|
|
137
|
+
return internalType.prop("ɵfac");
|
|
138
|
+
}
|
|
139
|
+
if (!unwrapForwardRefs) {
|
|
140
|
+
// The type is not wrapped in a `forwardRef()`, so we create a simple factory function that
|
|
141
|
+
// accepts a sub-type as an argument.
|
|
142
|
+
// ```
|
|
143
|
+
// factory: function(t) { return internalType.ɵfac(t); }
|
|
144
|
+
// ```
|
|
145
|
+
return createFactoryFunction(internalType);
|
|
146
|
+
}
|
|
147
|
+
// The internalType is actually wrapped in a `forwardRef()` so we need to resolve that before
|
|
148
|
+
// calling its factory.
|
|
149
|
+
// ```
|
|
150
|
+
// factory: function(t) { return core.resolveForwardRef(type).ɵfac(t); }
|
|
151
|
+
// ```
|
|
152
|
+
const unwrappedType = o
|
|
153
|
+
.importExpr(r3_identifiers_1.Identifiers.resolveForwardRef)
|
|
154
|
+
.callFn([internalType]);
|
|
155
|
+
return createFactoryFunction(unwrappedType);
|
|
156
|
+
}
|
|
157
|
+
function createFactoryFunction(type) {
|
|
158
|
+
return o.fn([new o.FnParam("t", o.DYNAMIC_TYPE)], [new o.ReturnStatement(type.callMethod("ɵfac", [o.variable("t")]))]);
|
|
159
|
+
}
|
|
@@ -0,0 +1,534 @@
|
|
|
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 { ParseSourceSpan } from '../parse_util';
|
|
9
|
+
export declare enum TypeModifier {
|
|
10
|
+
Const = 0
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class Type {
|
|
13
|
+
modifiers: TypeModifier[];
|
|
14
|
+
constructor(modifiers?: TypeModifier[]);
|
|
15
|
+
abstract visitType(visitor: TypeVisitor, context: any): any;
|
|
16
|
+
hasModifier(modifier: TypeModifier): boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare enum BuiltinTypeName {
|
|
19
|
+
Dynamic = 0,
|
|
20
|
+
Bool = 1,
|
|
21
|
+
String = 2,
|
|
22
|
+
Int = 3,
|
|
23
|
+
Number = 4,
|
|
24
|
+
Function = 5,
|
|
25
|
+
Inferred = 6,
|
|
26
|
+
None = 7
|
|
27
|
+
}
|
|
28
|
+
export declare class BuiltinType extends Type {
|
|
29
|
+
name: BuiltinTypeName;
|
|
30
|
+
constructor(name: BuiltinTypeName, modifiers?: TypeModifier[]);
|
|
31
|
+
visitType(visitor: TypeVisitor, context: any): any;
|
|
32
|
+
}
|
|
33
|
+
export declare class ExpressionType extends Type {
|
|
34
|
+
value: Expression;
|
|
35
|
+
typeParams: Type[] | null;
|
|
36
|
+
constructor(value: Expression, modifiers?: TypeModifier[], typeParams?: Type[] | null);
|
|
37
|
+
visitType(visitor: TypeVisitor, context: any): any;
|
|
38
|
+
}
|
|
39
|
+
export declare class ArrayType extends Type {
|
|
40
|
+
of: Type;
|
|
41
|
+
constructor(of: Type, modifiers?: TypeModifier[]);
|
|
42
|
+
visitType(visitor: TypeVisitor, context: any): any;
|
|
43
|
+
}
|
|
44
|
+
export declare class MapType extends Type {
|
|
45
|
+
valueType: Type | null;
|
|
46
|
+
constructor(valueType: Type | null | undefined, modifiers?: TypeModifier[]);
|
|
47
|
+
visitType(visitor: TypeVisitor, context: any): any;
|
|
48
|
+
}
|
|
49
|
+
export declare const DYNAMIC_TYPE: BuiltinType;
|
|
50
|
+
export declare const INFERRED_TYPE: BuiltinType;
|
|
51
|
+
export declare const BOOL_TYPE: BuiltinType;
|
|
52
|
+
export declare const INT_TYPE: BuiltinType;
|
|
53
|
+
export declare const NUMBER_TYPE: BuiltinType;
|
|
54
|
+
export declare const STRING_TYPE: BuiltinType;
|
|
55
|
+
export declare const FUNCTION_TYPE: BuiltinType;
|
|
56
|
+
export declare const NONE_TYPE: BuiltinType;
|
|
57
|
+
export interface TypeVisitor {
|
|
58
|
+
visitBuiltinType(type: BuiltinType, context: any): any;
|
|
59
|
+
visitExpressionType(type: ExpressionType, context: any): any;
|
|
60
|
+
visitArrayType(type: ArrayType, context: any): any;
|
|
61
|
+
visitMapType(type: MapType, context: any): any;
|
|
62
|
+
}
|
|
63
|
+
export declare enum UnaryOperator {
|
|
64
|
+
Minus = 0,
|
|
65
|
+
Plus = 1
|
|
66
|
+
}
|
|
67
|
+
export declare enum BinaryOperator {
|
|
68
|
+
Equals = 0,
|
|
69
|
+
NotEquals = 1,
|
|
70
|
+
Identical = 2,
|
|
71
|
+
NotIdentical = 3,
|
|
72
|
+
Minus = 4,
|
|
73
|
+
Plus = 5,
|
|
74
|
+
Divide = 6,
|
|
75
|
+
Multiply = 7,
|
|
76
|
+
Modulo = 8,
|
|
77
|
+
And = 9,
|
|
78
|
+
Or = 10,
|
|
79
|
+
BitwiseAnd = 11,
|
|
80
|
+
Lower = 12,
|
|
81
|
+
LowerEquals = 13,
|
|
82
|
+
Bigger = 14,
|
|
83
|
+
BiggerEquals = 15,
|
|
84
|
+
NullishCoalesce = 16
|
|
85
|
+
}
|
|
86
|
+
export declare function nullSafeIsEquivalent<T extends {
|
|
87
|
+
isEquivalent(other: T): boolean;
|
|
88
|
+
}>(base: T | null, other: T | null): boolean;
|
|
89
|
+
export declare function areAllEquivalent<T extends {
|
|
90
|
+
isEquivalent(other: T): boolean;
|
|
91
|
+
}>(base: T[], other: T[]): boolean;
|
|
92
|
+
export declare abstract class Expression {
|
|
93
|
+
type: Type | null;
|
|
94
|
+
sourceSpan: ParseSourceSpan | null;
|
|
95
|
+
constructor(type: Type | null | undefined, sourceSpan?: ParseSourceSpan | null);
|
|
96
|
+
abstract visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
97
|
+
/**
|
|
98
|
+
* Calculates whether this expression produces the same value as the given expression.
|
|
99
|
+
* Note: We don't check Types nor ParseSourceSpans nor function arguments.
|
|
100
|
+
*/
|
|
101
|
+
abstract isEquivalent(e: Expression): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Return true if the expression is constant.
|
|
104
|
+
*/
|
|
105
|
+
abstract isConstant(): boolean;
|
|
106
|
+
prop(name: string, sourceSpan?: ParseSourceSpan | null): ReadPropExpr;
|
|
107
|
+
callMethod(name: string | BuiltinMethod, params: Expression[], sourceSpan?: ParseSourceSpan | null): InvokeMethodExpr;
|
|
108
|
+
callFn(params: Expression[], sourceSpan?: ParseSourceSpan | null, pure?: boolean): InvokeFunctionExpr;
|
|
109
|
+
toStmt(): Statement;
|
|
110
|
+
}
|
|
111
|
+
export declare enum BuiltinVar {
|
|
112
|
+
This = 0,
|
|
113
|
+
Super = 1,
|
|
114
|
+
CatchError = 2,
|
|
115
|
+
CatchStack = 3
|
|
116
|
+
}
|
|
117
|
+
export declare class ReadVarExpr extends Expression {
|
|
118
|
+
name: string | null;
|
|
119
|
+
builtin: BuiltinVar | null;
|
|
120
|
+
constructor(name: string | BuiltinVar, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
121
|
+
isEquivalent(e: Expression): boolean;
|
|
122
|
+
isConstant(): boolean;
|
|
123
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
124
|
+
set(value: Expression): WriteVarExpr;
|
|
125
|
+
}
|
|
126
|
+
export declare class TypeofExpr extends Expression {
|
|
127
|
+
expr: Expression;
|
|
128
|
+
constructor(expr: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
129
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
130
|
+
isEquivalent(e: Expression): boolean;
|
|
131
|
+
isConstant(): boolean;
|
|
132
|
+
}
|
|
133
|
+
export declare class WrappedNodeExpr<T> extends Expression {
|
|
134
|
+
node: T;
|
|
135
|
+
constructor(node: T, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
136
|
+
isEquivalent(e: Expression): boolean;
|
|
137
|
+
isConstant(): boolean;
|
|
138
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
139
|
+
}
|
|
140
|
+
export declare class WriteVarExpr extends Expression {
|
|
141
|
+
name: string;
|
|
142
|
+
value: Expression;
|
|
143
|
+
constructor(name: string, value: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
144
|
+
isEquivalent(e: Expression): boolean;
|
|
145
|
+
isConstant(): boolean;
|
|
146
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
147
|
+
toDeclStmt(type?: Type | null, modifiers?: StmtModifier[]): DeclareVarStmt;
|
|
148
|
+
toConstDecl(): DeclareVarStmt;
|
|
149
|
+
}
|
|
150
|
+
export declare class WriteKeyExpr extends Expression {
|
|
151
|
+
receiver: Expression;
|
|
152
|
+
index: Expression;
|
|
153
|
+
value: Expression;
|
|
154
|
+
constructor(receiver: Expression, index: Expression, value: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
155
|
+
isEquivalent(e: Expression): boolean;
|
|
156
|
+
isConstant(): boolean;
|
|
157
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
158
|
+
}
|
|
159
|
+
export declare class WritePropExpr extends Expression {
|
|
160
|
+
receiver: Expression;
|
|
161
|
+
name: string;
|
|
162
|
+
value: Expression;
|
|
163
|
+
constructor(receiver: Expression, name: string, value: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
164
|
+
isEquivalent(e: Expression): boolean;
|
|
165
|
+
isConstant(): boolean;
|
|
166
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
167
|
+
}
|
|
168
|
+
export declare enum BuiltinMethod {
|
|
169
|
+
ConcatArray = 0,
|
|
170
|
+
SubscribeObservable = 1,
|
|
171
|
+
Bind = 2
|
|
172
|
+
}
|
|
173
|
+
export declare class InvokeMethodExpr extends Expression {
|
|
174
|
+
receiver: Expression;
|
|
175
|
+
args: Expression[];
|
|
176
|
+
name: string | null;
|
|
177
|
+
builtin: BuiltinMethod | null;
|
|
178
|
+
constructor(receiver: Expression, method: string | BuiltinMethod, args: Expression[], type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
179
|
+
isEquivalent(e: Expression): boolean;
|
|
180
|
+
isConstant(): boolean;
|
|
181
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
182
|
+
}
|
|
183
|
+
export declare class InvokeFunctionExpr extends Expression {
|
|
184
|
+
fn: Expression;
|
|
185
|
+
args: Expression[];
|
|
186
|
+
pure: boolean;
|
|
187
|
+
constructor(fn: Expression, args: Expression[], type?: Type | null, sourceSpan?: ParseSourceSpan | null, pure?: boolean);
|
|
188
|
+
isEquivalent(e: Expression): boolean;
|
|
189
|
+
isConstant(): boolean;
|
|
190
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
191
|
+
}
|
|
192
|
+
export declare class InstantiateExpr extends Expression {
|
|
193
|
+
classExpr: Expression;
|
|
194
|
+
args: Expression[];
|
|
195
|
+
constructor(classExpr: Expression, args: Expression[], type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
196
|
+
isEquivalent(e: Expression): boolean;
|
|
197
|
+
isConstant(): boolean;
|
|
198
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
199
|
+
}
|
|
200
|
+
export declare class LiteralExpr extends Expression {
|
|
201
|
+
value: number | string | boolean | null | undefined;
|
|
202
|
+
constructor(value: number | string | boolean | null | undefined, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
203
|
+
isEquivalent(e: Expression): boolean;
|
|
204
|
+
isConstant(): boolean;
|
|
205
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
206
|
+
}
|
|
207
|
+
export declare class TemplateLiteral {
|
|
208
|
+
elements: TemplateLiteralElement[];
|
|
209
|
+
expressions: Expression[];
|
|
210
|
+
constructor(elements: TemplateLiteralElement[], expressions: Expression[]);
|
|
211
|
+
}
|
|
212
|
+
export declare class TemplateLiteralElement {
|
|
213
|
+
text: string;
|
|
214
|
+
sourceSpan?: ParseSourceSpan;
|
|
215
|
+
rawText: string;
|
|
216
|
+
constructor(text: string, sourceSpan?: ParseSourceSpan, rawText?: string);
|
|
217
|
+
}
|
|
218
|
+
export declare abstract class MessagePiece {
|
|
219
|
+
text: string;
|
|
220
|
+
sourceSpan: ParseSourceSpan;
|
|
221
|
+
constructor(text: string, sourceSpan: ParseSourceSpan);
|
|
222
|
+
}
|
|
223
|
+
export declare class LiteralPiece extends MessagePiece {
|
|
224
|
+
}
|
|
225
|
+
export declare class PlaceholderPiece extends MessagePiece {
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* A structure to hold the cooked and raw strings of a template literal element, along with its
|
|
229
|
+
* source-span range.
|
|
230
|
+
*/
|
|
231
|
+
export interface CookedRawString {
|
|
232
|
+
cooked: string;
|
|
233
|
+
raw: string;
|
|
234
|
+
range: ParseSourceSpan | null;
|
|
235
|
+
}
|
|
236
|
+
export declare class ExternalExpr extends Expression {
|
|
237
|
+
value: ExternalReference;
|
|
238
|
+
typeParams: Type[] | null;
|
|
239
|
+
constructor(value: ExternalReference, type?: Type | null, typeParams?: Type[] | null, sourceSpan?: ParseSourceSpan | null);
|
|
240
|
+
isEquivalent(e: Expression): boolean;
|
|
241
|
+
isConstant(): boolean;
|
|
242
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
243
|
+
}
|
|
244
|
+
export declare class ExternalReference {
|
|
245
|
+
moduleName: string | null;
|
|
246
|
+
name: string | null;
|
|
247
|
+
runtime?: any | null;
|
|
248
|
+
constructor(moduleName: string | null, name: string | null, runtime?: any | null);
|
|
249
|
+
}
|
|
250
|
+
export declare class ConditionalExpr extends Expression {
|
|
251
|
+
condition: Expression;
|
|
252
|
+
falseCase: Expression | null;
|
|
253
|
+
trueCase: Expression;
|
|
254
|
+
constructor(condition: Expression, trueCase: Expression, falseCase?: Expression | null, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
255
|
+
isEquivalent(e: Expression): boolean;
|
|
256
|
+
isConstant(): boolean;
|
|
257
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
258
|
+
}
|
|
259
|
+
export declare class NotExpr extends Expression {
|
|
260
|
+
condition: Expression;
|
|
261
|
+
constructor(condition: Expression, sourceSpan?: ParseSourceSpan | null);
|
|
262
|
+
isEquivalent(e: Expression): boolean;
|
|
263
|
+
isConstant(): boolean;
|
|
264
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
265
|
+
}
|
|
266
|
+
export declare class AssertNotNull extends Expression {
|
|
267
|
+
condition: Expression;
|
|
268
|
+
constructor(condition: Expression, sourceSpan?: ParseSourceSpan | null);
|
|
269
|
+
isEquivalent(e: Expression): boolean;
|
|
270
|
+
isConstant(): boolean;
|
|
271
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
272
|
+
}
|
|
273
|
+
export declare class CastExpr extends Expression {
|
|
274
|
+
value: Expression;
|
|
275
|
+
constructor(value: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
276
|
+
isEquivalent(e: Expression): boolean;
|
|
277
|
+
isConstant(): boolean;
|
|
278
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
279
|
+
}
|
|
280
|
+
export declare class FnParam {
|
|
281
|
+
name: string;
|
|
282
|
+
type: Type | null;
|
|
283
|
+
constructor(name: string, type?: Type | null);
|
|
284
|
+
isEquivalent(param: FnParam): boolean;
|
|
285
|
+
}
|
|
286
|
+
export declare class FunctionExpr extends Expression {
|
|
287
|
+
params: FnParam[];
|
|
288
|
+
statements: Statement[];
|
|
289
|
+
name?: string | null;
|
|
290
|
+
constructor(params: FnParam[], statements: Statement[], type?: Type | null, sourceSpan?: ParseSourceSpan | null, name?: string | null);
|
|
291
|
+
isEquivalent(e: Expression): boolean;
|
|
292
|
+
isConstant(): boolean;
|
|
293
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
294
|
+
toDeclStmt(name: string, modifiers?: StmtModifier[]): DeclareFunctionStmt;
|
|
295
|
+
}
|
|
296
|
+
export declare class UnaryOperatorExpr extends Expression {
|
|
297
|
+
operator: UnaryOperator;
|
|
298
|
+
expr: Expression;
|
|
299
|
+
parens: boolean;
|
|
300
|
+
constructor(operator: UnaryOperator, expr: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null, parens?: boolean);
|
|
301
|
+
isEquivalent(e: Expression): boolean;
|
|
302
|
+
isConstant(): boolean;
|
|
303
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
304
|
+
}
|
|
305
|
+
export declare class BinaryOperatorExpr extends Expression {
|
|
306
|
+
operator: BinaryOperator;
|
|
307
|
+
rhs: Expression;
|
|
308
|
+
parens: boolean;
|
|
309
|
+
lhs: Expression;
|
|
310
|
+
constructor(operator: BinaryOperator, lhs: Expression, rhs: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null, parens?: boolean);
|
|
311
|
+
isEquivalent(e: Expression): boolean;
|
|
312
|
+
isConstant(): boolean;
|
|
313
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
314
|
+
}
|
|
315
|
+
export declare class ReadPropExpr extends Expression {
|
|
316
|
+
receiver: Expression;
|
|
317
|
+
name: string;
|
|
318
|
+
constructor(receiver: Expression, name: string, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
319
|
+
isEquivalent(e: Expression): boolean;
|
|
320
|
+
isConstant(): boolean;
|
|
321
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
322
|
+
set(value: Expression): WritePropExpr;
|
|
323
|
+
}
|
|
324
|
+
export declare class ReadKeyExpr extends Expression {
|
|
325
|
+
receiver: Expression;
|
|
326
|
+
index: Expression;
|
|
327
|
+
constructor(receiver: Expression, index: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
328
|
+
isEquivalent(e: Expression): boolean;
|
|
329
|
+
isConstant(): boolean;
|
|
330
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
331
|
+
set(value: Expression): WriteKeyExpr;
|
|
332
|
+
}
|
|
333
|
+
export declare class LiteralArrayExpr extends Expression {
|
|
334
|
+
entries: Expression[];
|
|
335
|
+
constructor(entries: Expression[], type?: Type | null, sourceSpan?: ParseSourceSpan | null);
|
|
336
|
+
isConstant(): boolean;
|
|
337
|
+
isEquivalent(e: Expression): boolean;
|
|
338
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
339
|
+
}
|
|
340
|
+
export declare class LiteralMapEntry {
|
|
341
|
+
key: string;
|
|
342
|
+
value: Expression;
|
|
343
|
+
quoted: boolean;
|
|
344
|
+
constructor(key: string, value: Expression, quoted: boolean);
|
|
345
|
+
isEquivalent(e: LiteralMapEntry): boolean;
|
|
346
|
+
}
|
|
347
|
+
export declare class LiteralMapExpr extends Expression {
|
|
348
|
+
entries: LiteralMapEntry[];
|
|
349
|
+
valueType: Type | null;
|
|
350
|
+
constructor(entries: LiteralMapEntry[], type?: MapType | null, sourceSpan?: ParseSourceSpan | null);
|
|
351
|
+
isEquivalent(e: Expression): boolean;
|
|
352
|
+
isConstant(): boolean;
|
|
353
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
354
|
+
}
|
|
355
|
+
export declare class CommaExpr extends Expression {
|
|
356
|
+
parts: Expression[];
|
|
357
|
+
constructor(parts: Expression[], sourceSpan?: ParseSourceSpan | null);
|
|
358
|
+
isEquivalent(e: Expression): boolean;
|
|
359
|
+
isConstant(): boolean;
|
|
360
|
+
visitExpression(visitor: ExpressionVisitor, context: any): any;
|
|
361
|
+
}
|
|
362
|
+
export interface ExpressionVisitor {
|
|
363
|
+
visitReadVarExpr(ast: ReadVarExpr, context: any): any;
|
|
364
|
+
visitWriteVarExpr(expr: WriteVarExpr, context: any): any;
|
|
365
|
+
visitWriteKeyExpr(expr: WriteKeyExpr, context: any): any;
|
|
366
|
+
visitWritePropExpr(expr: WritePropExpr, context: any): any;
|
|
367
|
+
visitInvokeMethodExpr(ast: InvokeMethodExpr, context: any): any;
|
|
368
|
+
visitInvokeFunctionExpr(ast: InvokeFunctionExpr, context: any): any;
|
|
369
|
+
visitInstantiateExpr(ast: InstantiateExpr, context: any): any;
|
|
370
|
+
visitLiteralExpr(ast: LiteralExpr, context: any): any;
|
|
371
|
+
visitExternalExpr(ast: ExternalExpr, context: any): any;
|
|
372
|
+
visitConditionalExpr(ast: ConditionalExpr, context: any): any;
|
|
373
|
+
visitNotExpr(ast: NotExpr, context: any): any;
|
|
374
|
+
visitAssertNotNullExpr(ast: AssertNotNull, context: any): any;
|
|
375
|
+
visitCastExpr(ast: CastExpr, context: any): any;
|
|
376
|
+
visitFunctionExpr(ast: FunctionExpr, context: any): any;
|
|
377
|
+
visitUnaryOperatorExpr(ast: UnaryOperatorExpr, context: any): any;
|
|
378
|
+
visitBinaryOperatorExpr(ast: BinaryOperatorExpr, context: any): any;
|
|
379
|
+
visitReadPropExpr(ast: ReadPropExpr, context: any): any;
|
|
380
|
+
visitReadKeyExpr(ast: ReadKeyExpr, context: any): any;
|
|
381
|
+
visitLiteralArrayExpr(ast: LiteralArrayExpr, context: any): any;
|
|
382
|
+
visitLiteralMapExpr(ast: LiteralMapExpr, context: any): any;
|
|
383
|
+
visitCommaExpr(ast: CommaExpr, context: any): any;
|
|
384
|
+
visitWrappedNodeExpr(ast: WrappedNodeExpr<any>, context: any): any;
|
|
385
|
+
visitTypeofExpr(ast: TypeofExpr, context: any): any;
|
|
386
|
+
}
|
|
387
|
+
export declare const THIS_EXPR: ReadVarExpr;
|
|
388
|
+
export declare const SUPER_EXPR: ReadVarExpr;
|
|
389
|
+
export declare const CATCH_ERROR_VAR: ReadVarExpr;
|
|
390
|
+
export declare const CATCH_STACK_VAR: ReadVarExpr;
|
|
391
|
+
export declare const NULL_EXPR: LiteralExpr;
|
|
392
|
+
export declare const TYPED_NULL_EXPR: LiteralExpr;
|
|
393
|
+
export declare enum StmtModifier {
|
|
394
|
+
Final = 0,
|
|
395
|
+
Private = 1,
|
|
396
|
+
Exported = 2,
|
|
397
|
+
Static = 3
|
|
398
|
+
}
|
|
399
|
+
export declare class LeadingComment {
|
|
400
|
+
text: string;
|
|
401
|
+
multiline: boolean;
|
|
402
|
+
trailingNewline: boolean;
|
|
403
|
+
constructor(text: string, multiline: boolean, trailingNewline: boolean);
|
|
404
|
+
toString(): string;
|
|
405
|
+
}
|
|
406
|
+
export declare class JSDocComment extends LeadingComment {
|
|
407
|
+
tags: JSDocTag[];
|
|
408
|
+
constructor(tags: JSDocTag[]);
|
|
409
|
+
toString(): string;
|
|
410
|
+
}
|
|
411
|
+
export declare abstract class Statement {
|
|
412
|
+
modifiers: StmtModifier[];
|
|
413
|
+
sourceSpan: ParseSourceSpan | null;
|
|
414
|
+
leadingComments?: LeadingComment[];
|
|
415
|
+
constructor(modifiers?: StmtModifier[], sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
416
|
+
/**
|
|
417
|
+
* Calculates whether this statement produces the same value as the given statement.
|
|
418
|
+
* Note: We don't check Types nor ParseSourceSpans nor function arguments.
|
|
419
|
+
*/
|
|
420
|
+
abstract isEquivalent(stmt: Statement): boolean;
|
|
421
|
+
abstract visitStatement(visitor: StatementVisitor, context: any): any;
|
|
422
|
+
hasModifier(modifier: StmtModifier): boolean;
|
|
423
|
+
addLeadingComment(leadingComment: LeadingComment): void;
|
|
424
|
+
}
|
|
425
|
+
export declare class DeclareVarStmt extends Statement {
|
|
426
|
+
name: string;
|
|
427
|
+
value?: Expression;
|
|
428
|
+
type: Type | null;
|
|
429
|
+
constructor(name: string, value?: Expression, type?: Type | null, modifiers?: StmtModifier[], sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
430
|
+
isEquivalent(stmt: Statement): boolean;
|
|
431
|
+
visitStatement(visitor: StatementVisitor, context: any): any;
|
|
432
|
+
}
|
|
433
|
+
export declare class DeclareFunctionStmt extends Statement {
|
|
434
|
+
name: string;
|
|
435
|
+
params: FnParam[];
|
|
436
|
+
statements: Statement[];
|
|
437
|
+
type: Type | null;
|
|
438
|
+
constructor(name: string, params: FnParam[], statements: Statement[], type?: Type | null, modifiers?: StmtModifier[], sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
439
|
+
isEquivalent(stmt: Statement): boolean;
|
|
440
|
+
visitStatement(visitor: StatementVisitor, context: any): any;
|
|
441
|
+
}
|
|
442
|
+
export declare class ExpressionStatement extends Statement {
|
|
443
|
+
expr: Expression;
|
|
444
|
+
constructor(expr: Expression, sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
445
|
+
isEquivalent(stmt: Statement): boolean;
|
|
446
|
+
visitStatement(visitor: StatementVisitor, context: any): any;
|
|
447
|
+
}
|
|
448
|
+
export declare class ReturnStatement extends Statement {
|
|
449
|
+
value: Expression;
|
|
450
|
+
constructor(value: Expression, sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
451
|
+
isEquivalent(stmt: Statement): boolean;
|
|
452
|
+
visitStatement(visitor: StatementVisitor, context: any): any;
|
|
453
|
+
}
|
|
454
|
+
export declare class AbstractClassPart {
|
|
455
|
+
type: Type | null;
|
|
456
|
+
modifiers: StmtModifier[];
|
|
457
|
+
constructor(type?: Type | null, modifiers?: StmtModifier[]);
|
|
458
|
+
hasModifier(modifier: StmtModifier): boolean;
|
|
459
|
+
}
|
|
460
|
+
export declare class ClassField extends AbstractClassPart {
|
|
461
|
+
name: string;
|
|
462
|
+
initializer?: Expression;
|
|
463
|
+
constructor(name: string, type?: Type | null, modifiers?: StmtModifier[], initializer?: Expression);
|
|
464
|
+
isEquivalent(f: ClassField): boolean;
|
|
465
|
+
}
|
|
466
|
+
export declare class ClassMethod extends AbstractClassPart {
|
|
467
|
+
name: string | null;
|
|
468
|
+
params: FnParam[];
|
|
469
|
+
body: Statement[];
|
|
470
|
+
constructor(name: string | null, params: FnParam[], body: Statement[], type?: Type | null, modifiers?: StmtModifier[]);
|
|
471
|
+
isEquivalent(m: ClassMethod): boolean;
|
|
472
|
+
}
|
|
473
|
+
export declare class ClassGetter extends AbstractClassPart {
|
|
474
|
+
name: string;
|
|
475
|
+
body: Statement[];
|
|
476
|
+
constructor(name: string, body: Statement[], type?: Type | null, modifiers?: StmtModifier[]);
|
|
477
|
+
isEquivalent(m: ClassGetter): boolean;
|
|
478
|
+
}
|
|
479
|
+
export declare class ClassStmt extends Statement {
|
|
480
|
+
name: string;
|
|
481
|
+
parent: Expression | null;
|
|
482
|
+
fields: ClassField[];
|
|
483
|
+
getters: ClassGetter[];
|
|
484
|
+
constructorMethod: ClassMethod;
|
|
485
|
+
methods: ClassMethod[];
|
|
486
|
+
constructor(name: string, parent: Expression | null, fields: ClassField[], getters: ClassGetter[], constructorMethod: ClassMethod, methods: ClassMethod[], modifiers?: StmtModifier[], sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
487
|
+
isEquivalent(stmt: Statement): boolean;
|
|
488
|
+
visitStatement(visitor: StatementVisitor, context: any): any;
|
|
489
|
+
}
|
|
490
|
+
export declare class IfStmt extends Statement {
|
|
491
|
+
condition: Expression;
|
|
492
|
+
trueCase: Statement[];
|
|
493
|
+
falseCase: Statement[];
|
|
494
|
+
constructor(condition: Expression, trueCase: Statement[], falseCase?: Statement[], sourceSpan?: ParseSourceSpan | null, leadingComments?: LeadingComment[]);
|
|
495
|
+
isEquivalent(stmt: Statement): boolean;
|
|
496
|
+
visitStatement(visitor: StatementVisitor, context: any): any;
|
|
497
|
+
}
|
|
498
|
+
export interface StatementVisitor {
|
|
499
|
+
visitDeclareVarStmt(stmt: DeclareVarStmt, context: any): any;
|
|
500
|
+
visitDeclareFunctionStmt(stmt: DeclareFunctionStmt, context: any): any;
|
|
501
|
+
visitExpressionStmt(stmt: ExpressionStatement, context: any): any;
|
|
502
|
+
visitReturnStmt(stmt: ReturnStatement, context: any): any;
|
|
503
|
+
visitDeclareClassStmt(stmt: ClassStmt, context: any): any;
|
|
504
|
+
visitIfStmt(stmt: IfStmt, context: any): any;
|
|
505
|
+
}
|
|
506
|
+
export declare function variable(name: string, type?: Type | null, sourceSpan?: ParseSourceSpan | null): ReadVarExpr;
|
|
507
|
+
export declare function importExpr(id: ExternalReference, typeParams?: Type[] | null, sourceSpan?: ParseSourceSpan | null): ExternalExpr;
|
|
508
|
+
export declare function expressionType(expr: Expression, typeModifiers?: TypeModifier[], typeParams?: Type[] | null): ExpressionType;
|
|
509
|
+
export declare function typeofExpr(expr: Expression): TypeofExpr;
|
|
510
|
+
export declare function literalArr(values: Expression[], type?: Type | null, sourceSpan?: ParseSourceSpan | null): LiteralArrayExpr;
|
|
511
|
+
export declare function literalMap(values: {
|
|
512
|
+
key: string;
|
|
513
|
+
quoted: boolean;
|
|
514
|
+
value: Expression;
|
|
515
|
+
}[], type?: MapType | null): LiteralMapExpr;
|
|
516
|
+
export declare function unary(operator: UnaryOperator, expr: Expression, type?: Type, sourceSpan?: ParseSourceSpan | null): UnaryOperatorExpr;
|
|
517
|
+
export declare function not(expr: Expression, sourceSpan?: ParseSourceSpan | null): NotExpr;
|
|
518
|
+
export declare function assertNotNull(expr: Expression, sourceSpan?: ParseSourceSpan | null): AssertNotNull;
|
|
519
|
+
export declare function fn(params: FnParam[], body: Statement[], type?: Type | null, sourceSpan?: ParseSourceSpan | null, name?: string | null): FunctionExpr;
|
|
520
|
+
export declare function ifStmt(condition: Expression, thenClause: Statement[], elseClause?: Statement[], sourceSpan?: ParseSourceSpan, leadingComments?: LeadingComment[]): IfStmt;
|
|
521
|
+
export declare function literal(value: any, type?: Type | null, sourceSpan?: ParseSourceSpan | null): LiteralExpr;
|
|
522
|
+
export declare function isNull(exp: Expression): boolean;
|
|
523
|
+
export declare const enum JSDocTagName {
|
|
524
|
+
Desc = "desc",
|
|
525
|
+
Id = "id",
|
|
526
|
+
Meaning = "meaning"
|
|
527
|
+
}
|
|
528
|
+
export declare type JSDocTag = {
|
|
529
|
+
tagName: JSDocTagName | string;
|
|
530
|
+
text?: string;
|
|
531
|
+
} | {
|
|
532
|
+
tagName?: undefined;
|
|
533
|
+
text: string;
|
|
534
|
+
};
|