@reckona/mreact-compiler 0.0.30 → 0.0.32
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/dist/compiler-module-context.d.ts +11 -0
- package/dist/compiler-module-context.d.ts.map +1 -0
- package/dist/compiler-module-context.js +16 -0
- package/dist/compiler-module-context.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +40 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +339 -28
- package/dist/internal.js.map +1 -1
- package/dist/oxc-component-references.d.ts.map +1 -1
- package/dist/oxc-component-references.js +226 -0
- package/dist/oxc-component-references.js.map +1 -1
- package/dist/oxc.d.ts +2 -0
- package/dist/oxc.d.ts.map +1 -1
- package/dist/oxc.js +8 -6
- package/dist/oxc.js.map +1 -1
- package/dist/transform.d.ts +4 -0
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +19 -7
- package/dist/transform.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface CompilerModuleContext {
|
|
2
|
+
code: string;
|
|
3
|
+
filename: string;
|
|
4
|
+
parseErrors: readonly unknown[];
|
|
5
|
+
program: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare function createCompilerModuleContextWithOxc(input: {
|
|
8
|
+
code: string;
|
|
9
|
+
filename?: string | undefined;
|
|
10
|
+
}): CompilerModuleContext;
|
|
11
|
+
//# sourceMappingURL=compiler-module-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-module-context.d.ts","sourceRoot":"","sources":["../src/compiler-module-context.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,kCAAkC,CAAC,KAAK,EAAE;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,GAAG,qBAAqB,CAcxB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
export function createCompilerModuleContextWithOxc(input) {
|
|
3
|
+
const filename = input.filename ?? "module.tsx";
|
|
4
|
+
const parsed = parseSync(filename, input.code, {
|
|
5
|
+
astType: "ts",
|
|
6
|
+
lang: "tsx",
|
|
7
|
+
sourceType: "module",
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
code: input.code,
|
|
11
|
+
filename,
|
|
12
|
+
parseErrors: parsed.errors,
|
|
13
|
+
program: parsed.program,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=compiler-module-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-module-context.js","sourceRoot":"","sources":["../src/compiler-module-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AASvC,MAAM,UAAU,kCAAkC,CAAC,KAGlD;IACC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC;IAChD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;QAC7C,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,KAAK;QACX,UAAU,EAAE,QAAQ;KACrB,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,QAAQ;QACR,WAAW,EAAE,MAAM,CAAC,MAAM;QAC1B,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { collectIdentifierReferenceNames, collectJsxComponentRootNames, collectStaticExportReferences, collectStaticImportReferences, collectStaticModuleSpecifiers, collectTopLevelValueExportNames, demoteTopLevelExportDeclarations, hasClientRuntimeSyntax, hasModuleDirective, hasTopLevelExportDeclaration, stripTopLevelExportDeclarations, } from "./internal.js";
|
|
2
|
-
export type { StaticExportReference, StaticImportReference } from "./internal.js";
|
|
1
|
+
export { collectIdentifierReferenceNames, collectJsxComponentRootNames, collectClientRouteModuleAnalysis, collectStaticExportReferences, collectStaticImportReferences, collectStaticModuleSpecifiers, collectTopLevelExportRenderInfo, collectTopLevelValueExportNames, demoteTopLevelExportDeclarations, hasClientRuntimeSyntax, hasModuleDirective, hasTopLevelExportDeclaration, stripTopLevelExportDeclarations, } from "./internal.js";
|
|
2
|
+
export type { StaticExportReference, StaticImportReference, StaticImportSpecifierReference, ClientRouteModuleAnalysis, ClientRouteStaticImportReference, TopLevelExportRenderInfo, } from "./internal.js";
|
|
3
3
|
export { formatDiagnostic } from "./diagnostics.js";
|
|
4
4
|
export { transform } from "./transform.js";
|
|
5
5
|
export type { CompileTarget, CompilerFrontend, CompilerMetadata, ClientReferenceMetadata, ComponentMetadata, Diagnostic, ModuleMetadata, ServerBootstrapMode, ServerEscapeOptions, RuntimeImport, ServerOutputMode, SourceLocation, TransformInput, TransformOutput, } from "./types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAC7B,6BAA6B,EAC7B,6BAA6B,EAC7B,+BAA+B,EAC/B,gCAAgC,EAChC,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,eAAe,CAAC;AACvB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,EAC5B,gCAAgC,EAChC,6BAA6B,EAC7B,6BAA6B,EAC7B,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,gCAAgC,EAChC,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,qBAAqB,EACrB,qBAAqB,EACrB,8BAA8B,EAC9B,yBAAyB,EACzB,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { collectIdentifierReferenceNames, collectJsxComponentRootNames, collectStaticExportReferences, collectStaticImportReferences, collectStaticModuleSpecifiers, collectTopLevelValueExportNames, demoteTopLevelExportDeclarations, hasClientRuntimeSyntax, hasModuleDirective, hasTopLevelExportDeclaration, stripTopLevelExportDeclarations, } from "./internal.js";
|
|
1
|
+
export { collectIdentifierReferenceNames, collectJsxComponentRootNames, collectClientRouteModuleAnalysis, collectStaticExportReferences, collectStaticImportReferences, collectStaticModuleSpecifiers, collectTopLevelExportRenderInfo, collectTopLevelValueExportNames, demoteTopLevelExportDeclarations, hasClientRuntimeSyntax, hasModuleDirective, hasTopLevelExportDeclaration, stripTopLevelExportDeclarations, } from "./internal.js";
|
|
2
2
|
export { formatDiagnostic } from "./diagnostics.js";
|
|
3
3
|
export { transform } from "./transform.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAC7B,6BAA6B,EAC7B,6BAA6B,EAC7B,+BAA+B,EAC/B,gCAAgC,EAChC,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,EAC5B,gCAAgC,EAChC,6BAA6B,EAC7B,6BAA6B,EAC7B,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,gCAAgC,EAChC,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,eAAe,CAAC;AASvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ModuleIr } from "./ir.js";
|
|
2
|
+
import { type CompilerModuleContext } from "./compiler-module-context.js";
|
|
3
|
+
export { transformCompilerModuleContext } from "./transform.js";
|
|
4
|
+
export type { CompilerModuleContext } from "./compiler-module-context.js";
|
|
2
5
|
import type { AnalyzeModuleOptions, CompileTarget, Diagnostic } from "./types.js";
|
|
3
6
|
export interface AnalyzeToIrInput {
|
|
4
7
|
code: string;
|
|
@@ -16,12 +19,40 @@ export interface StaticImportReference {
|
|
|
16
19
|
sideEffect: boolean;
|
|
17
20
|
source: string;
|
|
18
21
|
}
|
|
22
|
+
export interface StaticImportSpecifierReference {
|
|
23
|
+
importedName: string;
|
|
24
|
+
kind: "default" | "named" | "namespace";
|
|
25
|
+
localName: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ClientRouteStaticImportReference extends StaticImportReference {
|
|
28
|
+
specifiers: StaticImportSpecifierReference[];
|
|
29
|
+
}
|
|
19
30
|
export interface StaticExportReference {
|
|
20
31
|
exportedNames: string[];
|
|
21
32
|
exportAll: boolean;
|
|
22
33
|
source: string;
|
|
23
34
|
}
|
|
35
|
+
export interface TopLevelExportRenderInfo {
|
|
36
|
+
clientRuntime: boolean;
|
|
37
|
+
name: string;
|
|
38
|
+
renderedComponentRoots: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface ClientRouteModuleAnalysis {
|
|
41
|
+
clientRuntime: boolean;
|
|
42
|
+
hasUseClientDirective: boolean;
|
|
43
|
+
hasUseServerDirective: boolean;
|
|
44
|
+
identifierReferences: string[];
|
|
45
|
+
jsxComponentRoots: string[];
|
|
46
|
+
staticExports: StaticExportReference[];
|
|
47
|
+
staticImports: ClientRouteStaticImportReference[];
|
|
48
|
+
topLevelExportRenderInfo: TopLevelExportRenderInfo[];
|
|
49
|
+
}
|
|
24
50
|
export declare function analyzeToIr(input: AnalyzeToIrInput): AnalyzeToIrOutput;
|
|
51
|
+
export declare function analyzeCompilerModuleContextToIr(context: CompilerModuleContext, input: Omit<AnalyzeToIrInput, "code" | "filename">): AnalyzeToIrOutput;
|
|
52
|
+
export declare function createCompilerModuleContext(input: {
|
|
53
|
+
code: string;
|
|
54
|
+
filename?: string | undefined;
|
|
55
|
+
}): CompilerModuleContext;
|
|
25
56
|
export declare function hasTopLevelExportDeclaration(input: {
|
|
26
57
|
code: string;
|
|
27
58
|
filename?: string | undefined;
|
|
@@ -61,6 +92,15 @@ export declare function collectTopLevelValueExportNames(input: {
|
|
|
61
92
|
code: string;
|
|
62
93
|
filename?: string | undefined;
|
|
63
94
|
}): string[];
|
|
95
|
+
export declare function collectTopLevelExportRenderInfo(input: {
|
|
96
|
+
code: string;
|
|
97
|
+
filename?: string | undefined;
|
|
98
|
+
}): TopLevelExportRenderInfo[];
|
|
99
|
+
export declare function collectClientRouteModuleAnalysis(input: {
|
|
100
|
+
code: string;
|
|
101
|
+
filename?: string | undefined;
|
|
102
|
+
}): ClientRouteModuleAnalysis;
|
|
103
|
+
export declare function collectClientRouteModuleAnalysisFromContext(context: CompilerModuleContext): ClientRouteModuleAnalysis;
|
|
64
104
|
export declare function hasModuleDirective(input: {
|
|
65
105
|
code: string;
|
|
66
106
|
directive: string;
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAChE,YAAY,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,QAAQ,CAAC;IACb,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,EAA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
-
import { analyzeWithOxc } from "./oxc.js";
|
|
2
|
-
import {
|
|
1
|
+
import { analyzeCompilerModuleContextWithOxc, analyzeWithOxc, } from "./oxc.js";
|
|
2
|
+
import { createCompilerModuleContextWithOxc, } from "./compiler-module-context.js";
|
|
3
|
+
export { transformCompilerModuleContext } from "./transform.js";
|
|
3
4
|
export function analyzeToIr(input) {
|
|
4
5
|
return analyzeWithOxc(input);
|
|
5
6
|
}
|
|
7
|
+
export function analyzeCompilerModuleContextToIr(context, input) {
|
|
8
|
+
return analyzeCompilerModuleContextWithOxc(context, input);
|
|
9
|
+
}
|
|
10
|
+
export function createCompilerModuleContext(input) {
|
|
11
|
+
return createCompilerModuleContextWithOxc(input);
|
|
12
|
+
}
|
|
6
13
|
export function hasTopLevelExportDeclaration(input) {
|
|
7
14
|
const names = new Set(input.names);
|
|
8
15
|
const parsed = parseModule(input.code, input.filename);
|
|
@@ -49,10 +56,10 @@ export function collectStaticExportReferences(input) {
|
|
|
49
56
|
export function collectJsxComponentRootNames(input) {
|
|
50
57
|
const parsed = parseModule(input.code, input.filename);
|
|
51
58
|
const names = new Set();
|
|
52
|
-
const
|
|
59
|
+
const aliasState = createComponentAliasState();
|
|
53
60
|
collectJsxComponentRootNamesFromNode(parsed.program, names);
|
|
54
|
-
collectSimpleComponentAliasesFromNode(parsed.program,
|
|
55
|
-
expandJsxComponentAliasRoots(names, aliases);
|
|
61
|
+
collectSimpleComponentAliasesFromNode(parsed.program, aliasState);
|
|
62
|
+
expandJsxComponentAliasRoots(names, aliasState.aliases);
|
|
56
63
|
return Array.from(names).sort();
|
|
57
64
|
}
|
|
58
65
|
export function collectIdentifierReferenceNames(input) {
|
|
@@ -71,9 +78,84 @@ export function collectTopLevelValueExportNames(input) {
|
|
|
71
78
|
}
|
|
72
79
|
return Array.from(names).sort();
|
|
73
80
|
}
|
|
81
|
+
export function collectTopLevelExportRenderInfo(input) {
|
|
82
|
+
const parsed = parseModule(input.code, input.filename);
|
|
83
|
+
return collectTopLevelExportRenderInfoFromProgram(parsed.program);
|
|
84
|
+
}
|
|
85
|
+
export function collectClientRouteModuleAnalysis(input) {
|
|
86
|
+
const parsed = parseModule(input.code, input.filename);
|
|
87
|
+
return collectClientRouteModuleAnalysisFromContext(parsed);
|
|
88
|
+
}
|
|
89
|
+
export function collectClientRouteModuleAnalysisFromContext(context) {
|
|
90
|
+
const parsed = parseModuleContext(context);
|
|
91
|
+
const body = programBody(parsed.program);
|
|
92
|
+
const identifierReferences = new Set();
|
|
93
|
+
collectIdentifierReferenceNamesFromNode(parsed.program, identifierReferences);
|
|
94
|
+
return {
|
|
95
|
+
clientRuntime: hasClientRuntimeSyntaxNode(parsed.program),
|
|
96
|
+
hasUseClientDirective: hasModuleDirectiveInProgram(parsed.program, "use client"),
|
|
97
|
+
hasUseServerDirective: hasModuleDirectiveInProgram(parsed.program, "use server"),
|
|
98
|
+
identifierReferences: Array.from(identifierReferences).sort(),
|
|
99
|
+
jsxComponentRoots: collectJsxComponentRootNamesFromSubtree(parsed.program),
|
|
100
|
+
staticExports: body.flatMap(staticExportReference),
|
|
101
|
+
staticImports: body.flatMap(staticImportReference),
|
|
102
|
+
topLevelExportRenderInfo: collectTopLevelExportRenderInfoFromProgram(parsed.program),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function collectTopLevelExportRenderInfoFromProgram(program) {
|
|
106
|
+
const declarations = new Map();
|
|
107
|
+
const exported = new Map();
|
|
108
|
+
const directExports = new Map();
|
|
109
|
+
const aliasState = createComponentAliasState();
|
|
110
|
+
collectSimpleComponentAliasesFromNode(program, aliasState);
|
|
111
|
+
for (const statement of programBody(program)) {
|
|
112
|
+
collectTopLevelDeclarationReferences(statement, declarations);
|
|
113
|
+
if (statement.type === "ExportDefaultDeclaration") {
|
|
114
|
+
const declaration = readOptionalObject(statement.declaration);
|
|
115
|
+
directExports.set("default", declaration);
|
|
116
|
+
exported.set("default", "default");
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (statement.type !== "ExportNamedDeclaration") {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const declaration = readOptionalObject(statement.declaration);
|
|
123
|
+
if (declaration !== undefined) {
|
|
124
|
+
for (const name of exportedNames(statement)) {
|
|
125
|
+
exported.set(name, name);
|
|
126
|
+
directExports.set(name, declarationForExportedName(declaration, name) ?? declaration);
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const specifiers = Array.isArray(statement.specifiers) ? statement.specifiers.map(readObject) : [];
|
|
131
|
+
for (const specifier of specifiers) {
|
|
132
|
+
const exportedName = exportedNameForSpecifier(specifier);
|
|
133
|
+
const localName = localNameForExportSpecifier(specifier);
|
|
134
|
+
if (exportedName !== undefined && localName !== undefined) {
|
|
135
|
+
exported.set(exportedName, localName);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return [...exported.entries()]
|
|
140
|
+
.map(([name, localName]) => {
|
|
141
|
+
const node = directExports.get(name) ?? declarations.get(localName);
|
|
142
|
+
return node === undefined
|
|
143
|
+
? undefined
|
|
144
|
+
: {
|
|
145
|
+
clientRuntime: hasClientRuntimeSyntaxNode(node),
|
|
146
|
+
name,
|
|
147
|
+
renderedComponentRoots: collectJsxComponentRootNamesFromSubtree(node, aliasState.aliases),
|
|
148
|
+
};
|
|
149
|
+
})
|
|
150
|
+
.filter((item) => item !== undefined)
|
|
151
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
152
|
+
}
|
|
74
153
|
export function hasModuleDirective(input) {
|
|
75
154
|
const parsed = parseModule(input.code, input.filename);
|
|
76
|
-
|
|
155
|
+
return hasModuleDirectiveInProgram(parsed.program, input.directive);
|
|
156
|
+
}
|
|
157
|
+
function hasModuleDirectiveInProgram(program, expectedDirective) {
|
|
158
|
+
for (const statement of programBody(program)) {
|
|
77
159
|
if (statement.type !== "ExpressionStatement") {
|
|
78
160
|
return false;
|
|
79
161
|
}
|
|
@@ -81,7 +163,7 @@ export function hasModuleDirective(input) {
|
|
|
81
163
|
if (typeof directive !== "string") {
|
|
82
164
|
return false;
|
|
83
165
|
}
|
|
84
|
-
if (directive ===
|
|
166
|
+
if (directive === expectedDirective) {
|
|
85
167
|
return true;
|
|
86
168
|
}
|
|
87
169
|
}
|
|
@@ -92,15 +174,16 @@ export function hasClientRuntimeSyntax(input) {
|
|
|
92
174
|
return hasClientRuntimeSyntaxNode(parsed.program);
|
|
93
175
|
}
|
|
94
176
|
function parseModule(code, filename) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
177
|
+
return parseModuleContext(createCompilerModuleContext({ code, filename }));
|
|
178
|
+
}
|
|
179
|
+
function parseModuleContext(context) {
|
|
180
|
+
if (context.parseErrors.length > 0) {
|
|
181
|
+
throw new Error(context.parseErrors
|
|
182
|
+
.map((error) => readObject(error).message)
|
|
183
|
+
.filter((message) => typeof message === "string")
|
|
184
|
+
.join("\n"));
|
|
102
185
|
}
|
|
103
|
-
return
|
|
186
|
+
return context;
|
|
104
187
|
}
|
|
105
188
|
function programBody(program) {
|
|
106
189
|
const body = readObject(program).body;
|
|
@@ -131,6 +214,49 @@ function exportedNames(statement) {
|
|
|
131
214
|
return typeof name === "string" ? [name] : [];
|
|
132
215
|
});
|
|
133
216
|
}
|
|
217
|
+
function collectTopLevelDeclarationReferences(statement, declarations) {
|
|
218
|
+
const declaration = statement.type === "ExportNamedDeclaration"
|
|
219
|
+
? readOptionalObject(statement.declaration)
|
|
220
|
+
: statement;
|
|
221
|
+
if (declaration?.type === "FunctionDeclaration") {
|
|
222
|
+
const name = readOptionalObject(declaration.id)?.name;
|
|
223
|
+
if (typeof name === "string") {
|
|
224
|
+
declarations.set(name, declaration);
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (declaration?.type !== "VariableDeclaration") {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const declarators = Array.isArray(declaration.declarations)
|
|
232
|
+
? declaration.declarations.map(readObject)
|
|
233
|
+
: [];
|
|
234
|
+
for (const declarator of declarators) {
|
|
235
|
+
const id = readOptionalObject(declarator.id);
|
|
236
|
+
const name = typeof id?.name === "string" ? id.name : undefined;
|
|
237
|
+
if (name !== undefined) {
|
|
238
|
+
declarations.set(name, readOptionalObject(declarator.init) ?? declarator);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function declarationForExportedName(declaration, name) {
|
|
243
|
+
if (declaration.type === "VariableDeclaration") {
|
|
244
|
+
const declarators = Array.isArray(declaration.declarations)
|
|
245
|
+
? declaration.declarations.map(readObject)
|
|
246
|
+
: [];
|
|
247
|
+
for (const declarator of declarators) {
|
|
248
|
+
if (bindingNames(declarator.id).includes(name)) {
|
|
249
|
+
return readOptionalObject(declarator.init) ?? declarator;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return declaration;
|
|
254
|
+
}
|
|
255
|
+
function localNameForExportSpecifier(specifier) {
|
|
256
|
+
const local = readOptionalObject(specifier.local);
|
|
257
|
+
const name = local?.name ?? local?.value;
|
|
258
|
+
return typeof name === "string" ? name : undefined;
|
|
259
|
+
}
|
|
134
260
|
function exportDeclarationDemotion(code, statement, names) {
|
|
135
261
|
if (statement.type !== "ExportNamedDeclaration") {
|
|
136
262
|
return undefined;
|
|
@@ -260,6 +386,7 @@ function staticImportReference(statement) {
|
|
|
260
386
|
const specifiers = Array.isArray(statement.specifiers)
|
|
261
387
|
? statement.specifiers.map(readObject)
|
|
262
388
|
: [];
|
|
389
|
+
const importSpecifiers = specifiers.flatMap(staticImportSpecifierReference);
|
|
263
390
|
const localNames = specifiers
|
|
264
391
|
.filter((specifier) => specifier.importKind !== "type")
|
|
265
392
|
.flatMap((specifier) => {
|
|
@@ -271,9 +398,30 @@ function staticImportReference(statement) {
|
|
|
271
398
|
localNames,
|
|
272
399
|
sideEffect: localNames.length === 0,
|
|
273
400
|
source,
|
|
401
|
+
specifiers: importSpecifiers,
|
|
274
402
|
},
|
|
275
403
|
];
|
|
276
404
|
}
|
|
405
|
+
function staticImportSpecifierReference(specifier) {
|
|
406
|
+
if (specifier.importKind === "type") {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
const localName = readOptionalObject(specifier.local)?.name;
|
|
410
|
+
if (typeof localName !== "string") {
|
|
411
|
+
return [];
|
|
412
|
+
}
|
|
413
|
+
if (specifier.type === "ImportDefaultSpecifier") {
|
|
414
|
+
return [{ importedName: "default", kind: "default", localName }];
|
|
415
|
+
}
|
|
416
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
417
|
+
return [{ importedName: "*", kind: "namespace", localName }];
|
|
418
|
+
}
|
|
419
|
+
const imported = readOptionalObject(specifier.imported);
|
|
420
|
+
const importedName = imported?.name ?? imported?.value;
|
|
421
|
+
return typeof importedName === "string"
|
|
422
|
+
? [{ importedName, kind: "named", localName }]
|
|
423
|
+
: [];
|
|
424
|
+
}
|
|
277
425
|
function staticExportReference(statement) {
|
|
278
426
|
if (statement.type === "ExportAllDeclaration") {
|
|
279
427
|
if (statement.exportKind === "type") {
|
|
@@ -330,6 +478,14 @@ function collectJsxComponentRootNamesFromNode(node, names) {
|
|
|
330
478
|
collectJsxComponentRootNamesFromNode(value, names);
|
|
331
479
|
}
|
|
332
480
|
}
|
|
481
|
+
function collectJsxComponentRootNamesFromSubtree(node, outerAliases) {
|
|
482
|
+
const names = new Set();
|
|
483
|
+
const aliasState = createComponentAliasState(outerAliases);
|
|
484
|
+
collectJsxComponentRootNamesFromNode(node, names);
|
|
485
|
+
collectSimpleComponentAliasesFromNode(node, aliasState);
|
|
486
|
+
expandJsxComponentAliasRoots(names, aliasState.aliases);
|
|
487
|
+
return Array.from(names).sort();
|
|
488
|
+
}
|
|
333
489
|
function jsxNameRoot(node) {
|
|
334
490
|
if (node === undefined) {
|
|
335
491
|
return undefined;
|
|
@@ -342,10 +498,10 @@ function jsxNameRoot(node) {
|
|
|
342
498
|
}
|
|
343
499
|
return undefined;
|
|
344
500
|
}
|
|
345
|
-
function collectSimpleComponentAliasesFromNode(node,
|
|
501
|
+
function collectSimpleComponentAliasesFromNode(node, state) {
|
|
346
502
|
if (Array.isArray(node)) {
|
|
347
503
|
for (const child of node) {
|
|
348
|
-
collectSimpleComponentAliasesFromNode(child,
|
|
504
|
+
collectSimpleComponentAliasesFromNode(child, state);
|
|
349
505
|
}
|
|
350
506
|
return;
|
|
351
507
|
}
|
|
@@ -356,22 +512,114 @@ function collectSimpleComponentAliasesFromNode(node, aliases) {
|
|
|
356
512
|
if (typeof object.type === "string" && object.type.startsWith("TS")) {
|
|
357
513
|
return;
|
|
358
514
|
}
|
|
359
|
-
if (object.type === "
|
|
360
|
-
const
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
if (aliasName !== undefined && rootName !== undefined) {
|
|
365
|
-
aliases.set(aliasName, rootName);
|
|
515
|
+
if (object.type === "VariableDeclaration") {
|
|
516
|
+
const constant = object.kind === "const";
|
|
517
|
+
const declarations = Array.isArray(object.declarations) ? object.declarations : [];
|
|
518
|
+
for (const declaration of declarations) {
|
|
519
|
+
collectVariableDeclaratorComponentAliases(readOptionalObject(declaration), state, constant);
|
|
366
520
|
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (object.type === "VariableDeclarator") {
|
|
524
|
+
collectVariableDeclaratorComponentAliases(object, state, false);
|
|
525
|
+
}
|
|
526
|
+
if (object.type === "AssignmentExpression") {
|
|
527
|
+
collectAssignmentComponentAlias(object, state);
|
|
528
|
+
}
|
|
529
|
+
if (object.type === "CallExpression") {
|
|
530
|
+
collectObjectAssignComponentAliases(object, state);
|
|
367
531
|
}
|
|
368
532
|
for (const [key, value] of Object.entries(object)) {
|
|
369
533
|
if (key === "type" || key === "start" || key === "end" || key === "loc") {
|
|
370
534
|
continue;
|
|
371
535
|
}
|
|
372
|
-
collectSimpleComponentAliasesFromNode(value,
|
|
536
|
+
collectSimpleComponentAliasesFromNode(value, state);
|
|
373
537
|
}
|
|
374
538
|
}
|
|
539
|
+
function createComponentAliasState(aliases) {
|
|
540
|
+
return {
|
|
541
|
+
aliases: new Map(aliases),
|
|
542
|
+
stringConstants: new Map(),
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function collectVariableDeclaratorComponentAliases(object, state, constant) {
|
|
546
|
+
if (object?.type !== "VariableDeclarator") {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
const id = readOptionalObject(object.id);
|
|
550
|
+
const init = readOptionalObject(object.init);
|
|
551
|
+
const aliasName = typeof id?.name === "string" ? id.name : undefined;
|
|
552
|
+
if (aliasName === undefined) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (constant) {
|
|
556
|
+
const stringValue = stringExpressionValue(init, state);
|
|
557
|
+
if (stringValue !== undefined) {
|
|
558
|
+
state.stringConstants.set(aliasName, stringValue);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
collectObjectLiteralComponentAliases(aliasName, init, state);
|
|
562
|
+
const rootName = expressionRootName(init, state);
|
|
563
|
+
if (rootName !== undefined) {
|
|
564
|
+
state.aliases.set(aliasName, rootName);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function collectObjectLiteralComponentAliases(objectName, init, state) {
|
|
568
|
+
if (objectName === undefined || init?.type !== "ObjectExpression") {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const properties = Array.isArray(init.properties) ? init.properties : [];
|
|
572
|
+
for (const propertyValue of properties) {
|
|
573
|
+
const property = readOptionalObject(propertyValue);
|
|
574
|
+
if (property?.type !== "Property") {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
const keyName = propertyName(readOptionalObject(property.key), property.computed === true, state);
|
|
578
|
+
const valueName = expressionRootName(readOptionalObject(property.value), state);
|
|
579
|
+
if (keyName !== undefined && valueName !== undefined) {
|
|
580
|
+
state.aliases.set(`${objectName}.${keyName}`, valueName);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function collectAssignmentComponentAlias(node, state) {
|
|
585
|
+
if (node.operator !== "=") {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const left = readOptionalObject(node.left);
|
|
589
|
+
const right = readOptionalObject(node.right);
|
|
590
|
+
if (left?.type !== "MemberExpression") {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const objectRoot = expressionRootName(readOptionalObject(left.object), state);
|
|
594
|
+
const memberName = propertyName(readOptionalObject(left.property), left.computed === true, state);
|
|
595
|
+
const valueName = expressionRootName(right, state);
|
|
596
|
+
if (objectRoot !== undefined && memberName !== undefined && valueName !== undefined) {
|
|
597
|
+
state.aliases.set(`${objectRoot}.${memberName}`, valueName);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function collectObjectAssignComponentAliases(node, state) {
|
|
601
|
+
if (!isObjectAssignCall(node)) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const args = Array.isArray(node.arguments) ? node.arguments.map(readOptionalObject) : [];
|
|
605
|
+
const target = expressionRootName(args[0], state);
|
|
606
|
+
if (target === undefined) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
for (const source of args.slice(1)) {
|
|
610
|
+
collectObjectLiteralComponentAliases(target, source, state);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function isObjectAssignCall(node) {
|
|
614
|
+
const callee = readOptionalObject(node.callee);
|
|
615
|
+
if (callee?.type !== "MemberExpression" || callee.computed === true) {
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
const object = readOptionalObject(callee.object);
|
|
619
|
+
const property = readOptionalObject(callee.property);
|
|
620
|
+
return object?.type === "Identifier" && object.name === "Object" &&
|
|
621
|
+
property?.type === "Identifier" && property.name === "assign";
|
|
622
|
+
}
|
|
375
623
|
function expandJsxComponentAliasRoots(names, aliases) {
|
|
376
624
|
let changed = true;
|
|
377
625
|
while (changed) {
|
|
@@ -384,7 +632,7 @@ function expandJsxComponentAliasRoots(names, aliases) {
|
|
|
384
632
|
}
|
|
385
633
|
}
|
|
386
634
|
}
|
|
387
|
-
function expressionRootName(node) {
|
|
635
|
+
function expressionRootName(node, state) {
|
|
388
636
|
if (node === undefined) {
|
|
389
637
|
return undefined;
|
|
390
638
|
}
|
|
@@ -392,17 +640,80 @@ function expressionRootName(node) {
|
|
|
392
640
|
return node.name;
|
|
393
641
|
}
|
|
394
642
|
if (node.type === "MemberExpression") {
|
|
395
|
-
|
|
643
|
+
const objectRoot = expressionRootName(readOptionalObject(node.object), state);
|
|
644
|
+
const aliasedObjectRoot = objectRoot === undefined ? undefined : state?.aliases.get(objectRoot) ?? objectRoot;
|
|
645
|
+
const memberName = propertyName(readOptionalObject(node.property), node.computed === true, state);
|
|
646
|
+
const memberAlias = objectRoot !== undefined && memberName !== undefined
|
|
647
|
+
? state?.aliases.get(`${objectRoot}.${memberName}`) ??
|
|
648
|
+
(aliasedObjectRoot === undefined
|
|
649
|
+
? undefined
|
|
650
|
+
: state?.aliases.get(`${aliasedObjectRoot}.${memberName}`))
|
|
651
|
+
: undefined;
|
|
652
|
+
return memberAlias ??
|
|
653
|
+
(node.computed === true && memberName === undefined
|
|
654
|
+
? uniqueObjectMemberAlias(aliasedObjectRoot, state)
|
|
655
|
+
: aliasedObjectRoot);
|
|
656
|
+
}
|
|
657
|
+
if (node.type === "ConditionalExpression") {
|
|
658
|
+
return uniqueDefinedString([
|
|
659
|
+
expressionRootName(readOptionalObject(node.consequent), state),
|
|
660
|
+
expressionRootName(readOptionalObject(node.alternate), state),
|
|
661
|
+
]);
|
|
396
662
|
}
|
|
397
663
|
if (node.type === "ChainExpression" ||
|
|
398
664
|
node.type === "TSAsExpression" ||
|
|
399
665
|
node.type === "TSSatisfiesExpression" ||
|
|
400
666
|
node.type === "TSNonNullExpression" ||
|
|
401
667
|
node.type === "ParenthesizedExpression") {
|
|
402
|
-
return expressionRootName(readOptionalObject(node.expression));
|
|
668
|
+
return expressionRootName(readOptionalObject(node.expression), state);
|
|
669
|
+
}
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
function propertyName(node, computed, state) {
|
|
673
|
+
if (!computed && node?.type === "Identifier" && typeof node.name === "string") {
|
|
674
|
+
return node.name;
|
|
675
|
+
}
|
|
676
|
+
if (computed && node?.type === "Identifier" && typeof node.name === "string") {
|
|
677
|
+
return state?.stringConstants.get(node.name);
|
|
678
|
+
}
|
|
679
|
+
return stringExpressionValue(node, state);
|
|
680
|
+
}
|
|
681
|
+
function stringExpressionValue(node, state) {
|
|
682
|
+
if ((node?.type === "StringLiteral" || node?.type === "Literal") &&
|
|
683
|
+
typeof node.value === "string") {
|
|
684
|
+
return node.value;
|
|
685
|
+
}
|
|
686
|
+
if (node?.type === "ConditionalExpression") {
|
|
687
|
+
return uniqueDefinedString([
|
|
688
|
+
stringExpressionValue(readOptionalObject(node.consequent), state),
|
|
689
|
+
stringExpressionValue(readOptionalObject(node.alternate), state),
|
|
690
|
+
]);
|
|
691
|
+
}
|
|
692
|
+
if (node?.type === "Identifier" && typeof node.name === "string") {
|
|
693
|
+
return state?.stringConstants.get(node.name);
|
|
694
|
+
}
|
|
695
|
+
if (node?.type === "ChainExpression" ||
|
|
696
|
+
node?.type === "TSAsExpression" ||
|
|
697
|
+
node?.type === "TSSatisfiesExpression" ||
|
|
698
|
+
node?.type === "TSNonNullExpression" ||
|
|
699
|
+
node?.type === "ParenthesizedExpression") {
|
|
700
|
+
return stringExpressionValue(readOptionalObject(node.expression), state);
|
|
403
701
|
}
|
|
404
702
|
return undefined;
|
|
405
703
|
}
|
|
704
|
+
function uniqueObjectMemberAlias(objectName, state) {
|
|
705
|
+
if (objectName === undefined || state === undefined) {
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
const prefix = `${objectName}.`;
|
|
709
|
+
return uniqueDefinedString(Array.from(state.aliases.entries())
|
|
710
|
+
.filter(([key]) => key.startsWith(prefix))
|
|
711
|
+
.map(([, value]) => value));
|
|
712
|
+
}
|
|
713
|
+
function uniqueDefinedString(values) {
|
|
714
|
+
const unique = new Set(values.filter((value) => value !== undefined));
|
|
715
|
+
return unique.size === 1 ? Array.from(unique)[0] : undefined;
|
|
716
|
+
}
|
|
406
717
|
function collectIdentifierReferenceNamesFromNode(node, names) {
|
|
407
718
|
if (Array.isArray(node)) {
|
|
408
719
|
for (const child of node) {
|