@doubao-dev/taro-plugin-platform-doubao 0.10.2 → 0.11.0-rc.10

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 (80) hide show
  1. package/README.md +57 -152
  2. package/dist/compiler.d.ts +23 -13
  3. package/dist/compiler.js +44 -45
  4. package/dist/emit/index.d.ts +11 -0
  5. package/dist/emit/index.js +63 -0
  6. package/dist/index.js +8 -16
  7. package/dist/plans/host-deps.d.ts +45 -0
  8. package/dist/plans/host-deps.js +246 -0
  9. package/dist/plans/project-files.d.ts +8 -0
  10. package/dist/plans/project-files.js +309 -0
  11. package/dist/plans/pxtransform.d.ts +6 -0
  12. package/dist/{pxtransform.js → plans/pxtransform.js} +14 -17
  13. package/dist/plans/scaffold.d.ts +10 -0
  14. package/dist/plans/scaffold.js +114 -0
  15. package/dist/plans/sources/class-components.d.ts +11 -0
  16. package/dist/{class-components.js → plans/sources/class-components.js} +171 -59
  17. package/dist/plans/sources/dead-branches.d.ts +36 -0
  18. package/dist/plans/sources/dead-branches.js +415 -0
  19. package/dist/plans/sources/index.d.ts +36 -0
  20. package/dist/plans/sources/index.js +57 -0
  21. package/dist/plans/sources/styles.d.ts +7 -0
  22. package/dist/plans/sources/styles.js +111 -0
  23. package/dist/plans/sources/transform.d.ts +9 -0
  24. package/dist/plans/sources/transform.js +396 -0
  25. package/dist/plans/sources/vendor/bundle.d.ts +23 -0
  26. package/dist/plans/sources/vendor/bundle.js +221 -0
  27. package/dist/plans/sources/vendor/class-loader.d.ts +9 -0
  28. package/dist/plans/sources/vendor/class-loader.js +41 -0
  29. package/dist/plans/sources/vendor/index.d.ts +34 -0
  30. package/dist/plans/sources/vendor/index.js +62 -0
  31. package/dist/plans/sources/vendor/manifest.d.ts +43 -0
  32. package/dist/plans/sources/vendor/manifest.js +182 -0
  33. package/dist/plans/sources/vendor/output.d.ts +4 -0
  34. package/dist/plans/sources/vendor/output.js +68 -0
  35. package/dist/project/app.d.ts +3 -0
  36. package/dist/project/app.js +160 -0
  37. package/dist/project/defines.d.ts +3 -0
  38. package/dist/project/defines.js +89 -0
  39. package/dist/project/imports.d.ts +95 -0
  40. package/dist/project/imports.js +122 -0
  41. package/dist/project/index.d.ts +82 -0
  42. package/dist/project/index.js +182 -0
  43. package/dist/project/program.d.ts +15 -0
  44. package/dist/project/program.js +60 -0
  45. package/dist/project/resolver.d.ts +24 -0
  46. package/dist/project/resolver.js +96 -0
  47. package/dist/runner.d.ts +3 -2
  48. package/dist/runner.js +6 -4
  49. package/dist/shared/errors.d.ts +6 -0
  50. package/dist/shared/errors.js +16 -0
  51. package/dist/shared/layout.d.ts +32 -0
  52. package/dist/shared/layout.js +85 -0
  53. package/dist/shared/paths.d.ts +16 -0
  54. package/dist/shared/paths.js +83 -0
  55. package/dist/shared/syntax.d.ts +31 -0
  56. package/dist/shared/syntax.js +276 -0
  57. package/dist/verify.d.ts +4 -0
  58. package/dist/verify.js +35 -0
  59. package/package.json +3 -1
  60. package/dist/class-components.d.ts +0 -6
  61. package/dist/config.d.ts +0 -8
  62. package/dist/config.js +0 -274
  63. package/dist/file-system.d.ts +0 -21
  64. package/dist/file-system.js +0 -42
  65. package/dist/files.d.ts +0 -24
  66. package/dist/files.js +0 -256
  67. package/dist/platform-branches.d.ts +0 -4
  68. package/dist/platform-branches.js +0 -122
  69. package/dist/project-files.d.ts +0 -7
  70. package/dist/project-files.js +0 -129
  71. package/dist/project.d.ts +0 -48
  72. package/dist/project.js +0 -314
  73. package/dist/pxtransform.d.ts +0 -17
  74. package/dist/scaffold.d.ts +0 -15
  75. package/dist/scaffold.js +0 -103
  76. package/dist/transform.d.ts +0 -11
  77. package/dist/transform.js +0 -318
  78. package/dist/validate.d.ts +0 -4
  79. package/dist/validate.js +0 -27
  80. package/templates/taro.defines.ts +0 -2
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.printer = void 0;
7
+ exports.readSource = readSource;
8
+ exports.moduleName = moduleName;
9
+ exports.isTypeOnlyReference = isTypeOnlyReference;
10
+ exports.collectLiveSymbolUsage = collectLiveSymbolUsage;
11
+ exports.collectValueIdentifiers = collectValueIdentifiers;
12
+ exports.sanitizeAmbientDeclaration = sanitizeAmbientDeclaration;
13
+ exports.rewrite = rewrite;
14
+ const node_fs_1 = __importDefault(require("node:fs"));
15
+ const typescript_1 = __importDefault(require("typescript"));
16
+ const errors_1 = require("./errors");
17
+ const paths_1 = require("./paths");
18
+ /* TypeScript syntax helpers: parsing, module references, scope-aware symbol checks and specifier rewriting. */
19
+ exports.printer = typescript_1.default.createPrinter({ newLine: typescript_1.default.NewLineKind.LineFeed });
20
+ function readSource(filename) {
21
+ return typescript_1.default.createSourceFile(filename, node_fs_1.default.readFileSync(filename, 'utf8'), typescript_1.default.ScriptTarget.Latest, true);
22
+ }
23
+ function moduleName(node) {
24
+ if ((typescript_1.default.isImportDeclaration(node) || typescript_1.default.isExportDeclaration(node)) &&
25
+ node.moduleSpecifier &&
26
+ typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
27
+ return node.moduleSpecifier;
28
+ }
29
+ if (typescript_1.default.isImportTypeNode(node) &&
30
+ typescript_1.default.isLiteralTypeNode(node.argument) &&
31
+ typescript_1.default.isStringLiteral(node.argument.literal)) {
32
+ return node.argument.literal;
33
+ }
34
+ if (typescript_1.default.isCallExpression(node) &&
35
+ (node.expression.kind === typescript_1.default.SyntaxKind.ImportKeyword ||
36
+ (typescript_1.default.isIdentifier(node.expression) && node.expression.text === 'require'))) {
37
+ if (node.arguments.length !== 1 || !typescript_1.default.isStringLiteral(node.arguments[0])) {
38
+ (0, errors_1.fail)(`Dynamic module paths are unsupported in ${node.getSourceFile().fileName}`);
39
+ }
40
+ return node.arguments[0];
41
+ }
42
+ return undefined;
43
+ }
44
+ /**
45
+ * True when the reference is erased at compile time: `import type`, `export type`, `import('x').T`, or an
46
+ * import whose named bindings are all inline `type` specifiers.
47
+ */
48
+ function isTypeOnlyReference(node) {
49
+ if (typescript_1.default.isImportDeclaration(node)) {
50
+ const clause = node.importClause;
51
+ if (!clause) {
52
+ return false;
53
+ }
54
+ if (clause.isTypeOnly) {
55
+ return true;
56
+ }
57
+ return (!clause.name &&
58
+ !!clause.namedBindings &&
59
+ typescript_1.default.isNamedImports(clause.namedBindings) &&
60
+ clause.namedBindings.elements.length > 0 &&
61
+ clause.namedBindings.elements.every((element) => element.isTypeOnly));
62
+ }
63
+ if (typescript_1.default.isExportDeclaration(node)) {
64
+ return (node.isTypeOnly ||
65
+ (!!node.exportClause &&
66
+ typescript_1.default.isNamedExports(node.exportClause) &&
67
+ node.exportClause.elements.length > 0 &&
68
+ node.exportClause.elements.every((element) => element.isTypeOnly)));
69
+ }
70
+ return typescript_1.default.isImportTypeNode(node);
71
+ }
72
+ function importDeclarationLocalName(decl) {
73
+ if (typescript_1.default.isImportClause(decl)) {
74
+ return decl.name?.text;
75
+ }
76
+ if (typescript_1.default.isNamespaceImport(decl) || typescript_1.default.isImportSpecifier(decl)) {
77
+ return decl.name.text;
78
+ }
79
+ return undefined;
80
+ }
81
+ /**
82
+ * Stage 2 semantic collection on the original `ts.SourceFile` (skipping `deadNodes`):
83
+ * Uses `ts.TypeChecker` when available so local variables shadowing an import name are never mistaken for
84
+ * runtime uses of that import, and `typeof ImportedValue` (`TypeQueryNode`) is accurately classified.
85
+ */
86
+ function collectLiveSymbolUsage(source, checker, deadNodes) {
87
+ const valueImportNames = new Set();
88
+ const qualifiedTypeRoots = new Set();
89
+ const liveReferencedNames = new Set();
90
+ if (paths_1.declarationPattern.test(source.fileName)) {
91
+ return {
92
+ valueImportNames,
93
+ qualifiedTypeRoots,
94
+ liveReferencedNames
95
+ };
96
+ }
97
+ const recordReference = (identifier) => {
98
+ if (!checker) {
99
+ valueImportNames.add(identifier.text);
100
+ return;
101
+ }
102
+ const sym = identifier.parent && typescript_1.default.isShorthandPropertyAssignment(identifier.parent)
103
+ ? checker.getShorthandAssignmentValueSymbol(identifier.parent)
104
+ : checker.getSymbolAtLocation(identifier);
105
+ if (!sym?.declarations?.length) {
106
+ valueImportNames.add(identifier.text);
107
+ return;
108
+ }
109
+ for (const decl of sym.declarations) {
110
+ const importLocal = importDeclarationLocalName(decl);
111
+ if (importLocal) {
112
+ valueImportNames.add(importLocal);
113
+ }
114
+ }
115
+ };
116
+ // Collect all live identifier names (both type and value positions) for dead-import pruning.
117
+ const collectLiveNames = (node) => {
118
+ if (deadNodes?.has(node) || typescript_1.default.isImportDeclaration(node)) {
119
+ return;
120
+ }
121
+ if (typescript_1.default.isIdentifier(node)) {
122
+ liveReferencedNames.add(node.text);
123
+ }
124
+ typescript_1.default.forEachChild(node, collectLiveNames);
125
+ };
126
+ typescript_1.default.forEachChild(source, collectLiveNames);
127
+ // Collect qualified type roots (`React.FC`, `Taro.General.CallbackResult`) on live nodes.
128
+ const leftmost = (entity) => typescript_1.default.isIdentifier(entity) ? entity : leftmost(entity.left);
129
+ const visitTypes = (node) => {
130
+ if (deadNodes?.has(node) || typescript_1.default.isTypeQueryNode(node)) {
131
+ return;
132
+ }
133
+ if (typescript_1.default.isQualifiedName(node)) {
134
+ const rootId = leftmost(node.left);
135
+ if (!checker) {
136
+ qualifiedTypeRoots.add(rootId.text);
137
+ }
138
+ else {
139
+ const sym = checker.getSymbolAtLocation(rootId);
140
+ const isImportRoot = !sym?.declarations?.length ||
141
+ sym.declarations.some((decl) => typescript_1.default.isImportClause(decl) || typescript_1.default.isNamespaceImport(decl) || typescript_1.default.isImportSpecifier(decl));
142
+ if (isImportRoot) {
143
+ qualifiedTypeRoots.add(rootId.text);
144
+ }
145
+ }
146
+ }
147
+ typescript_1.default.forEachChild(node, visitTypes);
148
+ };
149
+ typescript_1.default.forEachChild(source, visitTypes);
150
+ // Collect runtime value references on live nodes.
151
+ const visitValues = (node) => {
152
+ if (deadNodes?.has(node)) {
153
+ return;
154
+ }
155
+ if (typescript_1.default.isExpressionWithTypeArguments(node)) {
156
+ visitValues(node.expression);
157
+ return;
158
+ }
159
+ if (typescript_1.default.isTypeNode(node) ||
160
+ typescript_1.default.isInterfaceDeclaration(node) ||
161
+ typescript_1.default.isTypeAliasDeclaration(node) ||
162
+ typescript_1.default.isImportDeclaration(node)) {
163
+ return;
164
+ }
165
+ if (typescript_1.default.isExportDeclaration(node)) {
166
+ if (node.isTypeOnly || node.moduleSpecifier) {
167
+ return;
168
+ }
169
+ if (node.exportClause && typescript_1.default.isNamedExports(node.exportClause)) {
170
+ for (const element of node.exportClause.elements) {
171
+ if (!element.isTypeOnly) {
172
+ const exportedId = element.propertyName ?? element.name;
173
+ if (!checker) {
174
+ valueImportNames.add(exportedId.text);
175
+ }
176
+ else {
177
+ const localSym = checker.getExportSpecifierLocalTargetSymbol(element);
178
+ if (!localSym?.declarations?.length) {
179
+ valueImportNames.add(exportedId.text);
180
+ }
181
+ else {
182
+ for (const decl of localSym.declarations) {
183
+ const importLocal = importDeclarationLocalName(decl);
184
+ if (importLocal) {
185
+ valueImportNames.add(importLocal);
186
+ }
187
+ }
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ return;
194
+ }
195
+ if (typescript_1.default.isHeritageClause(node) && node.token === typescript_1.default.SyntaxKind.ImplementsKeyword) {
196
+ return;
197
+ }
198
+ if (typescript_1.default.isIdentifier(node)) {
199
+ const parent = node.parent;
200
+ const isMemberName = parent &&
201
+ ((typescript_1.default.isPropertyAccessExpression(parent) && parent.name === node) ||
202
+ (typescript_1.default.isPropertyAssignment(parent) && parent.name === node) ||
203
+ (typescript_1.default.isMethodDeclaration(parent) && parent.name === node) ||
204
+ (typescript_1.default.isPropertyDeclaration(parent) && parent.name === node) ||
205
+ (typescript_1.default.isGetAccessorDeclaration(parent) && parent.name === node) ||
206
+ (typescript_1.default.isSetAccessorDeclaration(parent) && parent.name === node) ||
207
+ (typescript_1.default.isBindingElement(parent) && parent.propertyName === node) ||
208
+ (typescript_1.default.isJsxAttribute(parent) && parent.name === node));
209
+ if (!isMemberName) {
210
+ recordReference(node);
211
+ }
212
+ return;
213
+ }
214
+ typescript_1.default.forEachChild(node, visitValues);
215
+ };
216
+ typescript_1.default.forEachChild(source, visitValues);
217
+ return {
218
+ valueImportNames,
219
+ qualifiedTypeRoots,
220
+ liveReferencedNames
221
+ };
222
+ }
223
+ function collectValueIdentifiers(source) {
224
+ return collectLiveSymbolUsage(source).valueImportNames;
225
+ }
226
+ /**
227
+ * Strips ambient global `declare const/let/var <KEY>` declarations for constants that have already been
228
+ * AST-inlined via `defineConstants`, preventing multi-module global `.d.ts` redeclaration errors.
229
+ */
230
+ function sanitizeAmbientDeclaration(source, inlinedIdentifierKeys) {
231
+ if (!inlinedIdentifierKeys.size) {
232
+ return source;
233
+ }
234
+ let changed = false;
235
+ const statements = source.statements.flatMap((stmt) => {
236
+ if (typescript_1.default.isVariableStatement(stmt) &&
237
+ stmt.modifiers?.some((mod) => mod.kind === typescript_1.default.SyntaxKind.DeclareKeyword)) {
238
+ const kept = stmt.declarationList.declarations.filter((decl) => !(typescript_1.default.isIdentifier(decl.name) && inlinedIdentifierKeys.has(decl.name.text)));
239
+ if (kept.length === stmt.declarationList.declarations.length) {
240
+ return [stmt];
241
+ }
242
+ changed = true;
243
+ if (!kept.length) {
244
+ return [];
245
+ }
246
+ return [
247
+ typescript_1.default.factory.updateVariableStatement(stmt, stmt.modifiers, typescript_1.default.factory.updateVariableDeclarationList(stmt.declarationList, kept))
248
+ ];
249
+ }
250
+ return [stmt];
251
+ });
252
+ return changed ? typescript_1.default.factory.updateSourceFile(source, statements) : source;
253
+ }
254
+ function rewrite(source, replace) {
255
+ const result = typescript_1.default.transform(source, [
256
+ (context) => {
257
+ const replacements = new Map();
258
+ const visit = (node) => {
259
+ const literal = moduleName(node);
260
+ if (literal) {
261
+ replacements.set(literal, replace(literal, node));
262
+ }
263
+ const replacement = typescript_1.default.isStringLiteral(node) ? replacements.get(node) : undefined;
264
+ if (replacement !== undefined) {
265
+ return typescript_1.default.factory.createStringLiteral(replacement);
266
+ }
267
+ return typescript_1.default.visitEachChild(node, visit, context);
268
+ };
269
+ return (node) => typescript_1.default.visitNode(node, visit);
270
+ }
271
+ ]);
272
+ const output = exports.printer.printFile(result.transformed[0]);
273
+ result.dispose();
274
+ return output;
275
+ }
276
+ //# sourceMappingURL=syntax.js.map
@@ -0,0 +1,4 @@
1
+ import type { IPluginContext } from '@tarojs/service';
2
+ /** Checks that generated local imports resolve within `targetSource`. */
3
+ export declare function validateOutput(targetSource: string, helper: IPluginContext['helper']): void;
4
+ //# sourceMappingURL=verify.d.ts.map
package/dist/verify.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.validateOutput = validateOutput;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const typescript_1 = __importDefault(require("typescript"));
10
+ const errors_1 = require("./shared/errors");
11
+ const layout_1 = require("./shared/layout");
12
+ const paths_1 = require("./shared/paths");
13
+ const syntax_1 = require("./shared/syntax");
14
+ /** Checks that generated local imports resolve within `targetSource`. */
15
+ function validateOutput(targetSource, helper) {
16
+ const vendorRoot = node_path_1.default.join(targetSource, layout_1.vendorDirectory);
17
+ const sourceFiles = (0, paths_1.walk)(targetSource).filter((name) => paths_1.sourcePattern.test(name) && !(0, paths_1.inside)(vendorRoot, name));
18
+ for (const filename of sourceFiles) {
19
+ const validate = (node) => {
20
+ const literal = (0, syntax_1.moduleName)(node);
21
+ if (literal?.text.startsWith('.')) {
22
+ const candidate = node_path_1.default.resolve(node_path_1.default.dirname(filename), literal.text.replace(/[?#].*$/, ''));
23
+ const target = node_fs_1.default.statSync(candidate, { throwIfNoEntry: false })?.isFile()
24
+ ? candidate
25
+ : (0, paths_1.resolveSource)(helper, candidate);
26
+ if (!node_fs_1.default.statSync(target, { throwIfNoEntry: false })?.isFile() || !(0, paths_1.inside)(targetSource, target)) {
27
+ (0, errors_1.fail)(`Incomplete local dependency ${literal.text} in ${filename}`);
28
+ }
29
+ }
30
+ typescript_1.default.forEachChild(node, validate);
31
+ };
32
+ validate((0, syntax_1.readSource)(filename));
33
+ }
34
+ }
35
+ //# sourceMappingURL=verify.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-dev/taro-plugin-platform-doubao",
3
- "version": "0.10.2",
3
+ "version": "0.11.0-rc.10",
4
4
  "private": false,
5
5
  "description": "Generate standalone Doubao application source from Taro React projects",
6
6
  "type": "commonjs",
@@ -26,7 +26,9 @@
26
26
  "!dist/**/*.tsbuildinfo"
27
27
  ],
28
28
  "dependencies": {
29
+ "@rspack/core": "2.0.4",
29
30
  "postcss": "8.5.15",
31
+ "semver": "7.8.5",
30
32
  "typescript": "6.0.3"
31
33
  },
32
34
  "peerDependencies": {
@@ -1,6 +0,0 @@
1
- import ts from 'typescript';
2
- /** Wrap only the default page export; named exports and component identity inside the module stay intact. */
3
- export declare function wrapPage(source: ts.SourceFile, modulePath: string): ts.SourceFile;
4
- /** Keep class identity and refs intact; only wrap render results with a lifecycle subscriber. */
5
- export declare function wrapClassRenders(source: ts.SourceFile): ts.SourceFile;
6
- //# sourceMappingURL=class-components.d.ts.map
package/dist/config.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { FileSystem } from './file-system';
2
- type Value = null | string | number | boolean | Value[] | {
3
- [key: string]: Value;
4
- };
5
- export declare function readConfig(fileSystem: FileSystem, filename: string, macro: string, resolveLocal?: (from: string, specifier: string) => string | undefined): Record<string, Value>;
6
- export declare function appStyles(fileSystem: FileSystem, filename: string): string[];
7
- export {};
8
- //# sourceMappingURL=config.d.ts.map
package/dist/config.js DELETED
@@ -1,274 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readConfig = readConfig;
7
- exports.appStyles = appStyles;
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const typescript_1 = __importDefault(require("typescript"));
10
- const files_1 = require("./files");
11
- function readConfig(fileSystem, filename, macro, resolveLocal) {
12
- const active = new Set();
13
- const activeBindings = new Set();
14
- const sources = new Map();
15
- function sourceFile(file) {
16
- const cached = sources.get(file) ?? (0, files_1.readSource)(fileSystem, file);
17
- sources.set(file, cached);
18
- return cached;
19
- }
20
- function evaluate(node, source) {
21
- if (active.has(node)) {
22
- (0, files_1.fail)(`Circular config expression in ${source.fileName}`);
23
- }
24
- active.add(node);
25
- try {
26
- if (typescript_1.default.isParenthesizedExpression(node) || typescript_1.default.isAsExpression(node) || typescript_1.default.isSatisfiesExpression(node)) {
27
- return evaluate(node.expression, source);
28
- }
29
- if (typescript_1.default.isCallExpression(node) &&
30
- typescript_1.default.isIdentifier(node.expression) &&
31
- node.expression.text === macro &&
32
- node.arguments.length === 1) {
33
- return evaluate(node.arguments[0], source);
34
- }
35
- if (typescript_1.default.isStringLiteral(node) || typescript_1.default.isNoSubstitutionTemplateLiteral(node)) {
36
- return node.text;
37
- }
38
- if (typescript_1.default.isNumericLiteral(node)) {
39
- return Number(node.text);
40
- }
41
- if (node.kind === typescript_1.default.SyntaxKind.TrueKeyword || node.kind === typescript_1.default.SyntaxKind.FalseKeyword) {
42
- return node.kind === typescript_1.default.SyntaxKind.TrueKeyword;
43
- }
44
- if (node.kind === typescript_1.default.SyntaxKind.NullKeyword) {
45
- return null;
46
- }
47
- if (typescript_1.default.isArrayLiteralExpression(node)) {
48
- return node.elements.flatMap((item) => {
49
- if (typescript_1.default.isSpreadElement(item)) {
50
- const spread = evaluate(item.expression, source);
51
- if (!Array.isArray(spread)) {
52
- (0, files_1.fail)('Config array spread must be an array');
53
- }
54
- return spread;
55
- }
56
- return [evaluate(item, source)];
57
- });
58
- }
59
- if (typescript_1.default.isObjectLiteralExpression(node)) {
60
- const result = Object.create(null);
61
- for (const property of node.properties) {
62
- if (typescript_1.default.isSpreadAssignment(property)) {
63
- const spread = evaluate(property.expression, source);
64
- if (!spread || typeof spread !== 'object' || Array.isArray(spread)) {
65
- (0, files_1.fail)('Config object spread must be an object');
66
- }
67
- Object.assign(result, spread);
68
- }
69
- else if (typescript_1.default.isPropertyAssignment(property) &&
70
- (typescript_1.default.isIdentifier(property.name) || typescript_1.default.isStringLiteral(property.name))) {
71
- result[property.name.text] = evaluate(property.initializer, source);
72
- }
73
- else if (typescript_1.default.isShorthandPropertyAssignment(property)) {
74
- result[property.name.text] = evaluate(property.name, source);
75
- }
76
- else {
77
- (0, files_1.fail)(`Unsupported config property in ${source.fileName}`);
78
- }
79
- }
80
- return result;
81
- }
82
- if (typescript_1.default.isIdentifier(node)) {
83
- for (const statement of source.statements) {
84
- if (typescript_1.default.isVariableStatement(statement)) {
85
- const declaration = statement.declarationList.declarations.find((item) => typescript_1.default.isIdentifier(item.name) && item.name.text === node.text);
86
- if (declaration?.initializer) {
87
- return evaluate(declaration.initializer, source);
88
- }
89
- }
90
- if (typescript_1.default.isImportDeclaration(statement) && typescript_1.default.isStringLiteral(statement.moduleSpecifier)) {
91
- const clause = statement.importClause;
92
- const binding = clause?.namedBindings && typescript_1.default.isNamedImports(clause.namedBindings)
93
- ? clause.namedBindings.elements.find((item) => item.name.text === node.text)
94
- : undefined;
95
- if (clause?.name?.text === node.text || binding) {
96
- const specifier = statement.moduleSpecifier.text;
97
- const imported = specifier.startsWith('.')
98
- ? ((0, files_1.resolveSource)(fileSystem, node_path_1.default.resolve(node_path_1.default.dirname(source.fileName), specifier)) ??
99
- (0, files_1.fail)(`Missing config import ${specifier}`))
100
- : resolveLocal?.(source.fileName, specifier);
101
- if (imported && files_1.sourcePattern.test(imported)) {
102
- const importedName = binding ? (binding.propertyName ?? binding.name).text : 'default';
103
- const bindingKey = `${imported}:${importedName}`;
104
- if (activeBindings.has(bindingKey)) {
105
- (0, files_1.fail)(`Circular config expression in ${source.fileName}`);
106
- }
107
- activeBindings.add(bindingKey);
108
- try {
109
- const child = sourceFile(imported);
110
- if (binding) {
111
- return evaluate(typescript_1.default.factory.createIdentifier(importedName), child);
112
- }
113
- const assignment = child.statements.find(typescript_1.default.isExportAssignment) ??
114
- (0, files_1.fail)(`Missing default config export in ${imported}`);
115
- return evaluate(assignment.expression, child);
116
- }
117
- finally {
118
- activeBindings.delete(bindingKey);
119
- }
120
- }
121
- }
122
- }
123
- }
124
- }
125
- (0, files_1.fail)(`Config must be statically readable: ${typescript_1.default.isIdentifier(node) ? node.text : node.getText(source)} in ${source.fileName}`);
126
- }
127
- finally {
128
- active.delete(node);
129
- }
130
- }
131
- const source = sourceFile(filename);
132
- const assignment = source.statements.find(typescript_1.default.isExportAssignment) ?? (0, files_1.fail)(`Expected a default config export in ${filename}`);
133
- const value = evaluate(assignment.expression, source);
134
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
135
- (0, files_1.fail)(`Expected a config object in ${filename}`);
136
- }
137
- return value;
138
- }
139
- function isErasedAppImport(statement, valueIdentifiers) {
140
- if ((0, files_1.isTypeOnlyReference)(statement)) {
141
- return true;
142
- }
143
- const clause = statement.importClause;
144
- if (!clause ||
145
- !typescript_1.default.isStringLiteral(statement.moduleSpecifier) ||
146
- !(0, files_1.isTypeOnlyModule)(statement.moduleSpecifier.text)) {
147
- return false;
148
- }
149
- const boundNames = [];
150
- if (clause.name) {
151
- boundNames.push(clause.name);
152
- }
153
- if (clause.namedBindings) {
154
- if (typescript_1.default.isNamespaceImport(clause.namedBindings)) {
155
- boundNames.push(clause.namedBindings.name);
156
- }
157
- else {
158
- for (const element of clause.namedBindings.elements) {
159
- boundNames.push(element.name);
160
- }
161
- }
162
- }
163
- return boundNames.length > 0 && boundNames.every((identifier) => !valueIdentifiers.has(identifier.text));
164
- }
165
- function appStyles(fileSystem, filename) {
166
- const source = (0, files_1.readSource)(fileSystem, filename);
167
- const valueIdentifiers = (0, files_1.collectValueIdentifiers)(source);
168
- const styles = [];
169
- let app;
170
- const candidates = new Map();
171
- for (const statement of source.statements) {
172
- if (typescript_1.default.isFunctionDeclaration(statement) && statement.name) {
173
- candidates.set(statement.name.text, statement);
174
- }
175
- if (typescript_1.default.isVariableStatement(statement)) {
176
- for (const item of statement.declarationList.declarations) {
177
- if (!typescript_1.default.isIdentifier(item.name) ||
178
- !item.initializer ||
179
- !(typescript_1.default.isArrowFunction(item.initializer) || typescript_1.default.isFunctionExpression(item.initializer))) {
180
- (0, files_1.fail)('Additional App initialization is unsupported');
181
- }
182
- candidates.set(item.name.text, item.initializer);
183
- }
184
- }
185
- }
186
- for (const statement of source.statements) {
187
- if (typescript_1.default.isImportDeclaration(statement)) {
188
- if (!statement.importClause &&
189
- typescript_1.default.isStringLiteral(statement.moduleSpecifier) &&
190
- /\.(css|scss|sass|less)$/.test(statement.moduleSpecifier.text)) {
191
- styles.push(statement.moduleSpecifier.text);
192
- }
193
- else if (!isErasedAppImport(statement, valueIdentifiers)) {
194
- (0, files_1.fail)(`App supports type imports and styles only: ${filename}`);
195
- }
196
- }
197
- else if (typescript_1.default.isFunctionDeclaration(statement)) {
198
- if (statement.modifiers?.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.DefaultKeyword)) {
199
- app = statement;
200
- }
201
- }
202
- else if (typescript_1.default.isVariableStatement(statement)) {
203
- continue;
204
- }
205
- else if (typescript_1.default.isExportAssignment(statement)) {
206
- const value = typescript_1.default.isIdentifier(statement.expression)
207
- ? candidates.get(statement.expression.text)
208
- : statement.expression;
209
- if (!statement.isExportEquals &&
210
- value &&
211
- (typescript_1.default.isArrowFunction(value) || typescript_1.default.isFunctionExpression(value) || typescript_1.default.isFunctionDeclaration(value))) {
212
- app = value;
213
- }
214
- }
215
- else if (typescript_1.default.isTypeAliasDeclaration(statement) || typescript_1.default.isInterfaceDeclaration(statement)) {
216
- continue;
217
- }
218
- else {
219
- (0, files_1.fail)(`Unsupported App statement in ${filename}`);
220
- }
221
- }
222
- if (!app?.body ||
223
- app.parameters.length !== 1 ||
224
- app.parameters[0].dotDotDotToken ||
225
- app.parameters[0].initializer ||
226
- (!typescript_1.default.isObjectBindingPattern(app.parameters[0].name) && !typescript_1.default.isIdentifier(app.parameters[0].name)) ||
227
- app.modifiers?.some((modifier) => modifier.kind === typescript_1.default.SyntaxKind.AsyncKeyword) ||
228
- ('asteriskToken' in app && app.asteriskToken)) {
229
- (0, files_1.fail)('App must be a function receiving { children }; App providers and lifecycle hooks need explicit adaptation');
230
- }
231
- let body = typescript_1.default.isBlock(app.body) && app.body.statements.length === 1 && typescript_1.default.isReturnStatement(app.body.statements[0])
232
- ? app.body.statements[0].expression
233
- : app.body;
234
- while (body && typescript_1.default.isParenthesizedExpression(body)) {
235
- body = body.expression;
236
- }
237
- if (body && typescript_1.default.isJsxFragment(body)) {
238
- const meaningful = body.children.filter((child) => !(typescript_1.default.isJsxText(child) && !child.text.trim()));
239
- if (meaningful.length === 1 && typescript_1.default.isJsxExpression(meaningful[0]) && !meaningful[0].dotDotDotToken) {
240
- body = meaningful[0].expression;
241
- while (body && typescript_1.default.isParenthesizedExpression(body)) {
242
- body = body.expression;
243
- }
244
- }
245
- }
246
- const paramName = app.parameters[0].name;
247
- let returnsChildren = false;
248
- if (typescript_1.default.isObjectBindingPattern(paramName)) {
249
- const children = paramName.elements.find((item) => (item.propertyName ?? item.name).getText(source) === 'children');
250
- returnsChildren = Boolean(children &&
251
- !children.dotDotDotToken &&
252
- !children.initializer &&
253
- paramName.elements.length === 1 &&
254
- body &&
255
- typescript_1.default.isIdentifier(body) &&
256
- body.text === children.name.getText(source));
257
- }
258
- else if (typescript_1.default.isIdentifier(paramName)) {
259
- returnsChildren = Boolean(body &&
260
- typescript_1.default.isPropertyAccessExpression(body) &&
261
- !body.questionDotToken &&
262
- typescript_1.default.isIdentifier(body.expression) &&
263
- body.expression.text === paramName.text &&
264
- body.name.text === 'children');
265
- }
266
- if (!returnsChildren) {
267
- (0, files_1.fail)('App must return children without side effects');
268
- }
269
- if (candidates.size > 1) {
270
- (0, files_1.fail)('Additional App initialization is unsupported');
271
- }
272
- return styles;
273
- }
274
- //# sourceMappingURL=config.js.map
@@ -1,21 +0,0 @@
1
- import ts from 'typescript';
2
- interface DirectoryEntry {
3
- name: string;
4
- isDirectory(): boolean;
5
- isSymbolicLink(): boolean;
6
- }
7
- export interface FileSystem {
8
- readonly system: ts.System;
9
- exists(filename: string): boolean;
10
- realpath(filename: string): string;
11
- entries(directory: string): readonly DirectoryEntry[];
12
- readText(filename: string): string;
13
- writeText(filename: string, content: string): void;
14
- copyFile(source: string, destination: string): void;
15
- removeFile(filename: string): void;
16
- /** Stage writes and replace the output only after emit succeeds. */
17
- withOutput<T>(outputRoot: string, emit: (stage: string) => T): T;
18
- }
19
- export declare const nodeFileSystem: FileSystem;
20
- export {};
21
- //# sourceMappingURL=file-system.d.ts.map