@travetto/transformer 5.0.0-rc.1 → 5.0.0-rc.3
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/README.md +5 -9
- package/package.json +2 -2
- package/src/manager.ts +3 -3
- package/src/resolver/service.ts +11 -8
- package/src/state.ts +9 -8
- package/src/util/decorator.ts +20 -9
package/README.md
CHANGED
|
@@ -104,20 +104,16 @@ export class Test {
|
|
|
104
104
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
105
105
|
exports.TEST = void 0;
|
|
106
106
|
const tslib_1 = require("tslib");
|
|
107
|
-
const Ⲑ
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
static Ⲑinit = Ⲑ_runtime_1.RuntimeIndex.registerFunction(TEST, ᚕf, { hash: 649563175, lines: [1, 9] }, { COMPUTEAGE: { hash: 1286718349, lines: [6, 8] } }, false, false);
|
|
107
|
+
const Ⲑ_function_1 = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
|
|
108
|
+
var ᚕm = ["@travetto/transformer", "doc/upper"];
|
|
109
|
+
class TEST {
|
|
110
|
+
static Ⲑinit = Ⲑ_function_1.registerFunction(TEST, ᚕm, { hash: 649563175, lines: [1, 9] }, { COMPUTEAGE: { hash: 1286718349, lines: [6, 8, 7] } }, false, false);
|
|
112
111
|
NAME;
|
|
113
112
|
AGE;
|
|
114
113
|
DOB;
|
|
115
114
|
COMPUTEAGE() {
|
|
116
115
|
this['AGE'] = (Date.now() - this.DOB.getTime());
|
|
117
116
|
}
|
|
118
|
-
}
|
|
117
|
+
}
|
|
119
118
|
exports.TEST = TEST;
|
|
120
|
-
exports.TEST = TEST = tslib_1.__decorate([
|
|
121
|
-
Ⲑ_decorator_1.Register()
|
|
122
|
-
], TEST);
|
|
123
119
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/transformer",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.3",
|
|
4
4
|
"description": "Functionality for AST transformations, with transformer registration, and general utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"directory": "module/transformer"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@travetto/manifest": "^5.0.0-rc.
|
|
27
|
+
"@travetto/manifest": "^5.0.0-rc.2",
|
|
28
28
|
"tslib": "^2.6.3",
|
|
29
29
|
"typescript": "^5.5.3"
|
|
30
30
|
},
|
package/src/manager.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { ManifestIndex
|
|
3
|
+
import { ManifestIndex } from '@travetto/manifest';
|
|
4
4
|
|
|
5
5
|
import { NodeTransformer } from './types/visitor';
|
|
6
6
|
import { VisitorFactory } from './visitor';
|
|
@@ -19,12 +19,12 @@ export class TransformerManager {
|
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
21
|
static async create(manifestIndex: ManifestIndex): Promise<TransformerManager> {
|
|
22
|
-
const transformerFiles =
|
|
22
|
+
const transformerFiles = manifestIndex.find({ folder: f => f === '$transformer' }).map(f => f.sourceFile);
|
|
23
23
|
|
|
24
24
|
const transformers: NodeTransformer<TransformerState>[] = [];
|
|
25
25
|
|
|
26
26
|
for (const file of transformerFiles) { // Exclude based on blacklist
|
|
27
|
-
const entry =
|
|
27
|
+
const entry = manifestIndex.getEntry(file)!;
|
|
28
28
|
transformers.push(...getAllTransformers(await import(entry.import), entry.module));
|
|
29
29
|
}
|
|
30
30
|
|
package/src/resolver/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { path, ManifestIndex, ManifestModuleUtil } from '@travetto/manifest';
|
|
3
|
+
import { path, ManifestIndex, ManifestModuleUtil, IndexedFile } from '@travetto/manifest';
|
|
4
4
|
|
|
5
5
|
import type { AnyType, TransformResolver } from './types';
|
|
6
6
|
import { TypeCategorize, TypeBuilder } from './builder';
|
|
@@ -29,9 +29,9 @@ export class SimpleResolver implements TransformResolver {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Resolve an import
|
|
32
|
+
* Resolve an import for a file
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
getFileImport(file: string): IndexedFile | undefined {
|
|
35
35
|
let sourceFile = path.toPosix(file);
|
|
36
36
|
|
|
37
37
|
const type = ManifestModuleUtil.getFileType(file);
|
|
@@ -40,11 +40,14 @@ export class SimpleResolver implements TransformResolver {
|
|
|
40
40
|
sourceFile = `${sourceFile}.ts`;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
this.#manifestIndex.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
return this.#manifestIndex.getEntry(ManifestModuleUtil.getFileType(sourceFile) === 'ts' ? sourceFile : `${sourceFile}.js`) ??
|
|
44
|
+
this.#manifestIndex.getFromImport(ManifestModuleUtil.sourceToBlankExt(sourceFile).replace(/^.*node_modules\//, ''));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve an import name (e.g. @module/path/file) for a file
|
|
48
|
+
*/
|
|
49
|
+
getFileImportName(file: string, removeExt?: boolean): string {
|
|
50
|
+
const imp = this.getFileImport(file)?.import ?? file;
|
|
48
51
|
return removeExt ? ManifestModuleUtil.sourceToBlankExt(imp) : imp;
|
|
49
52
|
}
|
|
50
53
|
|
package/src/state.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
|
|
3
|
-
import { path, ManifestIndex } from '@travetto/manifest';
|
|
3
|
+
import { path, ManifestIndex, ManifestModuleUtil } from '@travetto/manifest';
|
|
4
4
|
|
|
5
5
|
import { ManagedType, AnyType, ForeignType } from './resolver/types';
|
|
6
6
|
import { State, DecoratorMeta, Transformer, ModuleNameⲐ } from './types/visitor';
|
|
@@ -33,7 +33,7 @@ export class TransformerState implements State {
|
|
|
33
33
|
|
|
34
34
|
#resolver: SimpleResolver;
|
|
35
35
|
#imports: ImportManager;
|
|
36
|
-
#
|
|
36
|
+
#modIdent: ts.Identifier;
|
|
37
37
|
#manifestIndex: ManifestIndex;
|
|
38
38
|
#syntheticIdentifiers = new Map<string, ts.Identifier>();
|
|
39
39
|
#decorators = new Map<string, ts.PropertyAccessExpression>();
|
|
@@ -261,17 +261,18 @@ export class TransformerState implements State {
|
|
|
261
261
|
/**
|
|
262
262
|
* Get filename identifier, regardless of module system
|
|
263
263
|
*/
|
|
264
|
-
|
|
265
|
-
if (this.#
|
|
266
|
-
this.#
|
|
267
|
-
const
|
|
268
|
-
|
|
264
|
+
getModuleIdentifier(): ts.Expression {
|
|
265
|
+
if (this.#modIdent === undefined) {
|
|
266
|
+
this.#modIdent = this.createIdentifier('ᚕm');
|
|
267
|
+
const entry = this.#resolver.getFileImport(this.source.fileName);
|
|
268
|
+
const decl = this.factory.createVariableDeclaration(this.#modIdent, undefined, undefined,
|
|
269
|
+
this.fromLiteral([entry?.module, ManifestModuleUtil.sourceToBlankExt(entry?.relativeFile ?? '')])
|
|
269
270
|
);
|
|
270
271
|
this.addStatements([
|
|
271
272
|
this.factory.createVariableStatement([], this.factory.createVariableDeclarationList([decl]))
|
|
272
273
|
], -1);
|
|
273
274
|
}
|
|
274
|
-
return this.#
|
|
275
|
+
return this.#modIdent;
|
|
275
276
|
}
|
|
276
277
|
|
|
277
278
|
/**
|
package/src/util/decorator.ts
CHANGED
|
@@ -6,20 +6,31 @@ import { CoreUtil } from './core';
|
|
|
6
6
|
*/
|
|
7
7
|
export class DecoratorUtil {
|
|
8
8
|
|
|
9
|
+
static #getIdentFromExpression(e: ts.Expression): ts.Identifier {
|
|
10
|
+
if (ts.isCallExpression(e) && ts.isIdentifier(e.expression)) {
|
|
11
|
+
return e.expression;
|
|
12
|
+
} else if (ts.isIdentifier(e)) {
|
|
13
|
+
return e;
|
|
14
|
+
} else if (ts.isCallExpression(e) && ts.isPropertyAccessExpression(e.expression) && ts.isIdentifier(e.expression.expression)) {
|
|
15
|
+
return e.expression.expression;
|
|
16
|
+
} else if (ts.isPropertyAccessExpression(e) && ts.isCallExpression(e.expression) && ts.isIdentifier(e.expression.expression)) {
|
|
17
|
+
return e.expression.expression;
|
|
18
|
+
} else if (ts.isParenthesizedExpression(e)) {
|
|
19
|
+
return this.#getIdentFromExpression(e.expression);
|
|
20
|
+
} else {
|
|
21
|
+
throw new Error('No Identifier');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* Get identifier for a decorator
|
|
11
27
|
*/
|
|
12
28
|
static getDecoratorIdent(d: ts.Decorator): ts.Identifier {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} else if (ts.isIdentifier(d.expression)) {
|
|
16
|
-
return d.expression;
|
|
17
|
-
} else if (ts.isCallExpression(d.expression) && ts.isPropertyAccessExpression(d.expression.expression) && ts.isIdentifier(d.expression.expression.expression)) {
|
|
18
|
-
return d.expression.expression.expression;
|
|
19
|
-
} else if (ts.isPropertyAccessExpression(d.expression) && ts.isCallExpression(d.expression.expression) && ts.isIdentifier(d.expression.expression.expression)) {
|
|
20
|
-
return d.expression.expression.expression;
|
|
21
|
-
} else {
|
|
29
|
+
const ident = this.#getIdentFromExpression(d.expression);
|
|
30
|
+
if (!ident) {
|
|
22
31
|
throw new Error('No Identifier');
|
|
32
|
+
} else {
|
|
33
|
+
return ident;
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
|