@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,114 @@
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.planScaffold = planScaffold;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const emit_1 = require("../emit");
10
+ const errors_1 = require("../shared/errors");
11
+ const layout_1 = require("../shared/layout");
12
+ const paths_1 = require("../shared/paths");
13
+ /** Files written into the generated `src/` in single-project mode, alongside transformed sources. */
14
+ const templateRoot = node_path_1.default.join(__dirname, '..', '..', 'templates');
15
+ function normalizeRoutePath(page) {
16
+ const clean = (0, paths_1.posixPath)(page).replace(/^\/+|\/+$/g, '');
17
+ return `/${clean}`;
18
+ }
19
+ /** Ensures no sibling exported module under `src/modules/*` already claims any of `pages`'s route paths. */
20
+ function checkCrossModuleRouteCollisions(model) {
21
+ const { layout, pages } = model;
22
+ if (!layout.moduleName) {
23
+ return;
24
+ }
25
+ const modulesRoot = node_path_1.default.join(layout.hostSource, layout_1.modulesDirectory);
26
+ if (!node_fs_1.default.existsSync(modulesRoot)) {
27
+ return;
28
+ }
29
+ const ourRoutes = new Set(pages.map(normalizeRoutePath));
30
+ for (const entry of node_fs_1.default.readdirSync(modulesRoot, { withFileTypes: true })) {
31
+ if (!entry.isDirectory() || entry.name === layout.moduleName) {
32
+ continue;
33
+ }
34
+ const siblingReportFile = node_path_1.default.join(modulesRoot, entry.name, layout_1.reportFile);
35
+ if (!node_fs_1.default.existsSync(siblingReportFile)) {
36
+ continue;
37
+ }
38
+ try {
39
+ const siblingReport = JSON.parse(node_fs_1.default.readFileSync(siblingReportFile, 'utf8'));
40
+ if (siblingReport.generator !== layout_1.generator || !Array.isArray(siblingReport.pages)) {
41
+ continue;
42
+ }
43
+ for (const siblingPage of siblingReport.pages) {
44
+ const siblingRoute = normalizeRoutePath(siblingPage);
45
+ if (ourRoutes.has(siblingRoute)) {
46
+ (0, errors_1.fail)(`Route path "${siblingRoute}" in module "${layout.moduleName}" conflicts with module "${entry.name}"`);
47
+ }
48
+ }
49
+ }
50
+ catch (error) {
51
+ if (error instanceof errors_1.DoubaoPluginError) {
52
+ throw error;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ function renderScaffoldFiles(model) {
58
+ const { options, layout, packageInfo, appConfig, pages, appDoubaoFile } = model;
59
+ const out = new Map();
60
+ if (layout.moduleName) {
61
+ const routeEntries = pages.map((page) => ({
62
+ entry: `${layout.entryPrefix}${(0, paths_1.posixPath)(page).replace(/^\/+/, '')}`,
63
+ path: normalizeRoutePath(page)
64
+ }));
65
+ const content = `export const routes = ${JSON.stringify(routeEntries, null, 2)};\n\n` + `export default routes;\n`;
66
+ out.set('routes.ts', content);
67
+ return out;
68
+ }
69
+ const darkMode = appConfig.darkMode ?? appConfig.darkmode;
70
+ const appId = options.appId ?? '';
71
+ const appConfigValue = {
72
+ appId,
73
+ name: options.name ?? packageInfo.name ?? appId,
74
+ pages,
75
+ ...(typeof darkMode === 'boolean' ? { darkMode } : {})
76
+ };
77
+ const placeholders = {
78
+ __APP_CONFIG__: JSON.stringify(appConfigValue, null, 2)
79
+ };
80
+ for (const filename of node_fs_1.default.readdirSync(templateRoot)) {
81
+ if (filename === 'app.ts' && appDoubaoFile) {
82
+ continue;
83
+ }
84
+ const content = node_fs_1.default
85
+ .readFileSync(node_path_1.default.join(templateRoot, filename), 'utf8')
86
+ .replaceAll(/__[A-Z_]+__/g, (key) => placeholders[key] ?? key);
87
+ out.set(filename, content);
88
+ }
89
+ return out;
90
+ }
91
+ /**
92
+ * Single-project mode: emits `app.ts` (unless `app.doubao.*` provided), `app.config.ts` and `taro-env.d.ts`.
93
+ * Module mode (`moduleName`): checks cross-module route uniqueness and emits `<moduleRoot>/routes.ts`.
94
+ */
95
+ function planScaffold(model) {
96
+ checkCrossModuleRouteCollisions(model);
97
+ const scaffoldFiles = renderScaffoldFiles(model);
98
+ return {
99
+ warnings: !model.layout.moduleName && model.appConfig.window
100
+ ? ['window configuration is not mapped; native Kit defaults apply']
101
+ : [],
102
+ // Runs after the sources, so a source file with a template's name is reported as a conflict.
103
+ writeSource(stagingDirectory) {
104
+ for (const [filename, content] of scaffoldFiles) {
105
+ const target = node_path_1.default.join(stagingDirectory, filename);
106
+ if (node_fs_1.default.existsSync(target)) {
107
+ (0, errors_1.fail)(`Source file conflicts with a generated file: ${filename}`);
108
+ }
109
+ (0, emit_1.writeText)(target, content);
110
+ }
111
+ }
112
+ };
113
+ }
114
+ //# sourceMappingURL=scaffold.js.map
@@ -0,0 +1,11 @@
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
+ /**
5
+ * Stage 2 (Read-Only): Detects React component class ranges on the original `ts.SourceFile`
6
+ * while AST nodes are still attached to `ts.TypeChecker`.
7
+ */
8
+ export declare function detectReactClassRanges(source: ts.SourceFile, checker?: ts.TypeChecker, deadNodes?: Set<ts.Node>): Set<string>;
9
+ /** Keep class identity and refs intact; only wrap render results with a lifecycle subscriber. */
10
+ export declare function wrapClassRenders(source: ts.SourceFile, checker?: ts.TypeChecker, deadNodes?: Set<ts.Node>, precomputedClassRanges?: Set<string>): ts.SourceFile;
11
+ //# sourceMappingURL=class-components.d.ts.map
@@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.wrapPage = wrapPage;
7
+ exports.detectReactClassRanges = detectReactClassRanges;
7
8
  exports.wrapClassRenders = wrapClassRenders;
8
9
  const typescript_1 = __importDefault(require("typescript"));
10
+ const imports_1 = require("../../project/imports");
9
11
  /** Wrap only the default page export; named exports and component identity inside the module stay intact. */
10
- function wrapPage(source, modulePath) {
12
+ function wrapPage(source, modulePath = imports_1.runtimeModules.internal) {
11
13
  let alias = '__adaptTaroPage';
12
14
  while (source.text.includes(alias)) {
13
15
  alias += '_';
@@ -66,77 +68,187 @@ function wrapPage(source, modulePath) {
66
68
  ...statements
67
69
  ]);
68
70
  }
69
- /** Keep class identity and refs intact; only wrap render results with a lifecycle subscriber. */
70
- function wrapClassRenders(source) {
71
- const bases = new Set();
72
- const namespaces = new Set();
73
- for (const statement of source.statements) {
74
- if (!typescript_1.default.isImportDeclaration(statement) ||
75
- !typescript_1.default.isStringLiteral(statement.moduleSpecifier) ||
76
- !['react', '@doubao-dev/framework'].includes(statement.moduleSpecifier.text) ||
77
- !statement.importClause ||
78
- statement.importClause.isTypeOnly) {
71
+ const reactBaseClasses = new Set(['Component', 'PureComponent']);
72
+ const pageLifecycleCallbacks = new Set(['componentDidShow', 'componentDidHide']);
73
+ const reactDeclarationPathPattern = /(?:^|\/)(?:node_modules\/(?:@types\/react|react|@lynx-js\/react|@doubao-dev\/(?:framework|taro-runtime)|@byted-doubao-apps\/framework)|packages\/(?:public\/)?(?:framework|taro-runtime))\//;
74
+ function memberName(node) {
75
+ return node.name && (typescript_1.default.isIdentifier(node.name) || typescript_1.default.isStringLiteral(node.name))
76
+ ? node.name.text
77
+ : undefined;
78
+ }
79
+ function hasPageLifecycleCallback(node) {
80
+ return node.members.some((member) => pageLifecycleCallbacks.has(memberName(member) ?? ''));
81
+ }
82
+ function isReactRuntimeImport(node) {
83
+ return Boolean(node &&
84
+ typescript_1.default.isImportDeclaration(node) &&
85
+ typescript_1.default.isStringLiteral(node.moduleSpecifier) &&
86
+ imports_1.reactComponentModules.has(node.moduleSpecifier.text) &&
87
+ node.importClause &&
88
+ !node.importClause.isTypeOnly);
89
+ }
90
+ function isDirectTypeOnlyImport(expression, checker) {
91
+ const rootId = typescript_1.default.isIdentifier(expression)
92
+ ? expression
93
+ : typescript_1.default.isPropertyAccessExpression(expression) && typescript_1.default.isIdentifier(expression.expression)
94
+ ? expression.expression
95
+ : undefined;
96
+ if (!rootId) {
97
+ return false;
98
+ }
99
+ const decl = checker.getSymbolAtLocation(rootId)?.declarations?.[0];
100
+ if (!decl) {
101
+ return false;
102
+ }
103
+ if (typescript_1.default.isImportSpecifier(decl)) {
104
+ return Boolean(decl.isTypeOnly || decl.parent.parent.isTypeOnly);
105
+ }
106
+ if (typescript_1.default.isImportClause(decl)) {
107
+ return Boolean(decl.isTypeOnly);
108
+ }
109
+ if (typescript_1.default.isNamespaceImport(decl)) {
110
+ return Boolean(decl.parent.isTypeOnly);
111
+ }
112
+ return false;
113
+ }
114
+ function isReactComponentClassViaChecker(node, checker, visited = new Set()) {
115
+ if (visited.has(node)) {
116
+ return false;
117
+ }
118
+ visited.add(node);
119
+ for (const clause of node.heritageClauses ?? []) {
120
+ if (clause.token !== typescript_1.default.SyntaxKind.ExtendsKeyword) {
79
121
  continue;
80
122
  }
81
- const { name, namedBindings } = statement.importClause;
82
- if (name) {
83
- namespaces.add(name.text);
84
- }
85
- if (namedBindings && typescript_1.default.isNamespaceImport(namedBindings)) {
86
- namespaces.add(namedBindings.name.text);
87
- }
88
- if (namedBindings && typescript_1.default.isNamedImports(namedBindings)) {
89
- for (const binding of namedBindings.elements) {
90
- if (!binding.isTypeOnly &&
91
- ['Component', 'PureComponent'].includes((binding.propertyName ?? binding.name).text)) {
92
- bases.add(binding.name.text);
123
+ for (const { expression } of clause.types) {
124
+ if (isDirectTypeOnlyImport(expression, checker)) {
125
+ continue;
126
+ }
127
+ if (typescript_1.default.isPropertyAccessExpression(expression) &&
128
+ typescript_1.default.isIdentifier(expression.expression) &&
129
+ reactBaseClasses.has(expression.name.text)) {
130
+ const nsDecl = checker.getSymbolAtLocation(expression.expression)?.declarations?.[0];
131
+ if (nsDecl &&
132
+ (typescript_1.default.isImportClause(nsDecl) || typescript_1.default.isNamespaceImport(nsDecl)) &&
133
+ isReactRuntimeImport(typescript_1.default.isImportClause(nsDecl) ? nsDecl.parent : nsDecl.parent.parent)) {
134
+ return true;
135
+ }
136
+ }
137
+ const rawSym = checker.getSymbolAtLocation(expression);
138
+ let aliasedSym = rawSym;
139
+ if (rawSym && rawSym.flags & typescript_1.default.SymbolFlags.Alias) {
140
+ try {
141
+ aliasedSym = checker.getAliasedSymbol(rawSym);
142
+ }
143
+ catch {
144
+ // Unresolved external module when @types/react is absent; inspect raw import declaration below.
93
145
  }
94
146
  }
147
+ let resolvedToKnownClass = false;
148
+ for (const sym of new Set([rawSym, aliasedSym])) {
149
+ for (const decl of sym?.declarations ?? []) {
150
+ if (typescript_1.default.isImportSpecifier(decl) &&
151
+ !decl.isTypeOnly &&
152
+ isReactRuntimeImport(decl.parent.parent.parent) &&
153
+ reactBaseClasses.has((decl.propertyName ?? decl.name).text)) {
154
+ return true;
155
+ }
156
+ const fileName = decl.getSourceFile().fileName.replaceAll('\\', '/');
157
+ if (reactBaseClasses.has(sym?.name ?? '') && reactDeclarationPathPattern.test(fileName)) {
158
+ return true;
159
+ }
160
+ const classTarget = typescript_1.default.isClassLike(decl)
161
+ ? decl
162
+ : typescript_1.default.isVariableDeclaration(decl) && decl.initializer && typescript_1.default.isClassExpression(decl.initializer)
163
+ ? decl.initializer
164
+ : undefined;
165
+ if (classTarget) {
166
+ resolvedToKnownClass = true;
167
+ if (isReactComponentClassViaChecker(classTarget, checker, visited)) {
168
+ return true;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ if (!resolvedToKnownClass && hasPageLifecycleCallback(node)) {
174
+ return true;
175
+ }
95
176
  }
96
177
  }
178
+ return false;
179
+ }
180
+ /** Minimal no-lib/no-resolve `TypeChecker` for standalone single-file transforms (e.g. Rspack vendor loader). */
181
+ function createStandaloneChecker(source) {
182
+ const program = typescript_1.default.createProgram([source.fileName], {
183
+ target: typescript_1.default.ScriptTarget.Latest,
184
+ allowJs: true,
185
+ jsx: typescript_1.default.JsxEmit.Preserve,
186
+ noLib: true,
187
+ noResolve: true,
188
+ skipLibCheck: true
189
+ }, {
190
+ getSourceFile: (fileName) => (fileName === source.fileName ? source : undefined),
191
+ writeFile: () => { },
192
+ getDefaultLibFileName: () => 'lib.d.ts',
193
+ useCaseSensitiveFileNames: () => true,
194
+ getCanonicalFileName: (fileName) => fileName,
195
+ getCurrentDirectory: () => '',
196
+ getNewLine: () => '\n',
197
+ fileExists: (fileName) => fileName === source.fileName,
198
+ readFile: () => undefined
199
+ });
200
+ return program.getTypeChecker();
201
+ }
202
+ function classRangeKey(node) {
203
+ return `${node.pos}:${node.end}`;
204
+ }
205
+ /**
206
+ * Stage 2 (Read-Only): Detects React component class ranges on the original `ts.SourceFile`
207
+ * while AST nodes are still attached to `ts.TypeChecker`.
208
+ */
209
+ function detectReactClassRanges(source, checker, deadNodes) {
210
+ const ranges = new Set();
211
+ if (!checker) {
212
+ return ranges;
213
+ }
214
+ const visit = (node) => {
215
+ if (deadNodes?.has(node)) {
216
+ return;
217
+ }
218
+ if (typescript_1.default.isClassLike(node) && isReactComponentClassViaChecker(node, checker)) {
219
+ ranges.add(classRangeKey(node));
220
+ }
221
+ typescript_1.default.forEachChild(node, visit);
222
+ };
223
+ typescript_1.default.forEachChild(source, visit);
224
+ return ranges;
225
+ }
226
+ /** Keep class identity and refs intact; only wrap render results with a lifecycle subscriber. */
227
+ function wrapClassRenders(source, checker, deadNodes, precomputedClassRanges) {
97
228
  const classes = [];
98
229
  const collect = (node) => {
230
+ if (deadNodes?.has(node)) {
231
+ return;
232
+ }
99
233
  if (typescript_1.default.isClassLike(node)) {
100
234
  classes.push(node);
101
235
  }
102
236
  typescript_1.default.forEachChild(node, collect);
103
237
  };
104
238
  collect(source);
105
- const components = new Set();
106
- const memberName = (node) => node.name && (typescript_1.default.isIdentifier(node.name) || typescript_1.default.isStringLiteral(node.name)) ? node.name.text : undefined;
107
- // Include local subclasses, including those that inherit their page callbacks.
108
- let changed = true;
109
- while (changed) {
110
- changed = false;
111
- for (const node of classes) {
112
- if (components.has(node)) {
113
- continue;
114
- }
115
- const reactBase = node.heritageClauses?.some((clause) => clause.token === typescript_1.default.SyntaxKind.ExtendsKeyword &&
116
- clause.types.some(({ expression }) => typescript_1.default.isIdentifier(expression)
117
- ? bases.has(expression.text)
118
- : typescript_1.default.isPropertyAccessExpression(expression) &&
119
- typescript_1.default.isIdentifier(expression.expression) &&
120
- namespaces.has(expression.expression.text) &&
121
- ['Component', 'PureComponent'].includes(expression.name.text)));
122
- // A cross-file base cannot be resolved here, so a subclass that declares page callbacks counts too.
123
- // Classes without `extends` are plain classes, never components.
124
- const inheritsWithCallback = node.heritageClauses?.some((clause) => clause.token === typescript_1.default.SyntaxKind.ExtendsKeyword) &&
125
- node.members.some((member) => ['componentDidShow', 'componentDidHide'].includes(memberName(member) ?? ''));
126
- if (!reactBase && !inheritsWithCallback) {
127
- continue;
128
- }
129
- components.add(node);
130
- if (node.name) {
131
- bases.add(node.name.text);
132
- }
133
- if (typescript_1.default.isClassExpression(node) &&
134
- typescript_1.default.isVariableDeclaration(node.parent) &&
135
- typescript_1.default.isIdentifier(node.parent.name)) {
136
- bases.add(node.parent.name.text);
137
- }
138
- changed = true;
139
- }
239
+ if (!classes.length) {
240
+ return source;
241
+ }
242
+ let components;
243
+ if (precomputedClassRanges) {
244
+ components = new Set(classes.filter((node) => precomputedClassRanges.has(classRangeKey(node))));
245
+ }
246
+ else {
247
+ const activeChecker = checker ?? createStandaloneChecker(source);
248
+ components = new Set(classes.filter((node) => isReactComponentClassViaChecker(node, activeChecker)));
249
+ }
250
+ if (!components.size) {
251
+ return source;
140
252
  }
141
253
  let alias = '__renderTaroClass';
142
254
  while (source.text.includes(alias)) {
@@ -201,7 +313,7 @@ function wrapClassRenders(source) {
201
313
  return typescript_1.default.factory.updateSourceFile(transformed, [
202
314
  typescript_1.default.factory.createImportDeclaration(undefined, typescript_1.default.factory.createImportClause(false, undefined, typescript_1.default.factory.createNamedImports([
203
315
  typescript_1.default.factory.createImportSpecifier(false, typescript_1.default.factory.createIdentifier('renderClassComponent'), typescript_1.default.factory.createIdentifier(alias))
204
- ])), typescript_1.default.factory.createStringLiteral('@doubao-dev/taro-runtime/internal')),
316
+ ])), typescript_1.default.factory.createStringLiteral(imports_1.runtimeModules.internal)),
205
317
  ...transformed.statements
206
318
  ]);
207
319
  }
@@ -0,0 +1,36 @@
1
+ import ts from 'typescript';
2
+ type StaticPrimitive = string | number | boolean | null | undefined;
3
+ type StaticValue = {
4
+ known: true;
5
+ value: StaticPrimitive;
6
+ typeofResult: string;
7
+ } | {
8
+ known: false;
9
+ typeofResult?: string;
10
+ };
11
+ interface CompiledDefineEntry {
12
+ rawExpression: string;
13
+ staticValue: StaticValue;
14
+ }
15
+ export interface CompiledDefines {
16
+ identifiers: Map<string, CompiledDefineEntry>;
17
+ chains: Map<string, CompiledDefineEntry>;
18
+ chainPrefixes: Set<string>;
19
+ customKeys: Set<string>;
20
+ }
21
+ export interface BranchAnalysis {
22
+ deadNodes: Set<ts.Node>;
23
+ branchDecisions: Map<ts.Node, boolean>;
24
+ defineReplacements: Map<ts.Node, string>;
25
+ deadIdentifierNames: Set<string>;
26
+ }
27
+ export declare function compileDefines(defines: Record<string, string>): CompiledDefines;
28
+ /**
29
+ * Stage 1 (Read-Only): Evaluates `defineConstants`/`env` and marks dead conditional branches in application
30
+ * `src/` files directly on the original `ts.SourceFile` while AST nodes stay bound to `ts.TypeChecker`.
31
+ */
32
+ export declare function analyzeSourceBranches(source: ts.SourceFile, compiled: CompiledDefines, checker?: ts.TypeChecker): BranchAnalysis;
33
+ /** Stage 3: Replaces global constants, prunes dead branches, and strips dead imports across all modules. */
34
+ export declare function applyDefinesAndPruneBranches(source: ts.SourceFile, analysis: BranchAnalysis, liveReferencedNames: Set<string>): ts.SourceFile;
35
+ export {};
36
+ //# sourceMappingURL=dead-branches.d.ts.map