@drawcall/glts 0.3.1 → 0.4.0
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 +92 -4
- package/dist/GLTSLoader.d.ts +2 -1
- package/dist/GLTSLoader.d.ts.map +1 -1
- package/dist/GLTSLoader.js +114 -36
- package/dist/GLTSLoader.js.map +1 -1
- package/dist/asset-exports.d.ts +12 -0
- package/dist/asset-exports.d.ts.map +1 -0
- package/dist/asset-exports.js +82 -0
- package/dist/asset-exports.js.map +1 -0
- package/dist/asset.d.ts +3 -0
- package/dist/asset.d.ts.map +1 -0
- package/dist/asset.js +5 -0
- package/dist/asset.js.map +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/inline-analysis.d.ts +63 -0
- package/dist/inline-analysis.d.ts.map +1 -0
- package/dist/inline-analysis.js +288 -0
- package/dist/inline-analysis.js.map +1 -0
- package/dist/inline.d.ts.map +1 -1
- package/dist/inline.js +16 -225
- package/dist/inline.js.map +1 -1
- package/dist/loading.d.ts +12 -0
- package/dist/loading.d.ts.map +1 -0
- package/dist/loading.js +111 -0
- package/dist/loading.js.map +1 -0
- package/dist/module-graph.d.ts +4 -7
- package/dist/module-graph.d.ts.map +1 -1
- package/dist/module-graph.js +7 -23
- package/dist/module-graph.js.map +1 -1
- package/dist/root.d.ts +20 -0
- package/dist/root.d.ts.map +1 -0
- package/dist/root.js +111 -0
- package/dist/root.js.map +1 -0
- package/dist/runtime.d.ts +7 -5
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +49 -9
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface SourceRange {
|
|
2
|
+
readonly start: number;
|
|
3
|
+
readonly end: number;
|
|
4
|
+
}
|
|
5
|
+
export interface LocalImport extends SourceRange {
|
|
6
|
+
readonly local: string;
|
|
7
|
+
readonly url: URL;
|
|
8
|
+
}
|
|
9
|
+
export type ExternalImport = {
|
|
10
|
+
readonly kind: "side-effect";
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly source: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "binding";
|
|
15
|
+
readonly imported: string;
|
|
16
|
+
readonly local: string;
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
readonly typeOnly: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type DefaultClass = {
|
|
22
|
+
readonly kind: "named";
|
|
23
|
+
readonly classStart: number;
|
|
24
|
+
readonly exportStart: number;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: "anonymous";
|
|
28
|
+
readonly classEnd: number;
|
|
29
|
+
readonly classStart: number;
|
|
30
|
+
readonly exportStart: number;
|
|
31
|
+
};
|
|
32
|
+
export interface EntryModule {
|
|
33
|
+
readonly externals: readonly ExternalImport[];
|
|
34
|
+
readonly imports: readonly LocalImport[];
|
|
35
|
+
readonly insertAt: number;
|
|
36
|
+
readonly source: string;
|
|
37
|
+
}
|
|
38
|
+
export interface DependencyModule {
|
|
39
|
+
readonly defaultClass: DefaultClass;
|
|
40
|
+
readonly externals: readonly ExternalImport[];
|
|
41
|
+
readonly imports: readonly LocalImport[];
|
|
42
|
+
readonly metaURLs: readonly SourceRange[];
|
|
43
|
+
readonly metaURL: string;
|
|
44
|
+
readonly path: string;
|
|
45
|
+
readonly removals: readonly SourceRange[];
|
|
46
|
+
readonly source: string;
|
|
47
|
+
readonly url: URL;
|
|
48
|
+
}
|
|
49
|
+
interface ModuleOptions {
|
|
50
|
+
readonly path: string;
|
|
51
|
+
readonly resolveImport: (specifier: string) => URL | undefined;
|
|
52
|
+
readonly source: string;
|
|
53
|
+
}
|
|
54
|
+
interface DependencyModuleOptions extends ModuleOptions {
|
|
55
|
+
readonly metaURL: string;
|
|
56
|
+
readonly url: URL;
|
|
57
|
+
}
|
|
58
|
+
export declare function failInline(message: string, path: string, phase: "resolve" | "transform", importChain?: readonly string[], cause?: unknown): never;
|
|
59
|
+
export declare function analyzeEntryModule(options: ModuleOptions): EntryModule;
|
|
60
|
+
export declare function analyzeDependencyModule(options: DependencyModuleOptions): DependencyModule;
|
|
61
|
+
export declare function validateInlineSyntax(source: string): void;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=inline-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-analysis.d.ts","sourceRoot":"","sources":["../src/inline-analysis.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;CACnB;AAED,MAAM,MAAM,cAAc,GACtB;IACE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEN,MAAM,MAAM,YAAY,GACpB;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACv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B;AAED,UAAU,uBAAwB,SAAQ,aAAa;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;CACnB;AAeD,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,SAAS,GAAG,WAAW,EAC9B,WAAW,GAAE,SAAS,MAAM,EAAO,EACnC,KAAK,CAAC,EAAE,OAAO,GACd,KAAK,CAEP;AAqSD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAkBtE;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CAgElB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEzD"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import { traverseFast } from "@babel/types";
|
|
3
|
+
import { GLTSError } from "./errors.js";
|
|
4
|
+
const previewExportNames = new Set([
|
|
5
|
+
"previewCamera",
|
|
6
|
+
"previewLighting"
|
|
7
|
+
]);
|
|
8
|
+
export function failInline(message, path, phase, importChain = [], cause) {
|
|
9
|
+
throw new GLTSError(message, { url: path, phase, importChain }, cause);
|
|
10
|
+
}
|
|
11
|
+
function sourceRange(node, path) {
|
|
12
|
+
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
13
|
+
failInline("Parser returned a node without a source range", path, "transform");
|
|
14
|
+
}
|
|
15
|
+
return { start: node.start, end: node.end };
|
|
16
|
+
}
|
|
17
|
+
function parseModule(source, path) {
|
|
18
|
+
try {
|
|
19
|
+
return parse(source, {
|
|
20
|
+
plugins: [
|
|
21
|
+
"decorators-legacy",
|
|
22
|
+
"deferredImportEvaluation",
|
|
23
|
+
"sourcePhaseImports",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
sourceFilename: path,
|
|
27
|
+
sourceType: "module"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
failInline("Unable to parse TypeScript source", path, "transform", [], error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function metaURLRanges(ast, path) {
|
|
35
|
+
const importMetas = new Set();
|
|
36
|
+
const metaURLs = new Map();
|
|
37
|
+
traverseFast(ast, (node) => {
|
|
38
|
+
if (node.type === "ImportExpression") {
|
|
39
|
+
failInline("Dynamic imports are not supported", path, "transform");
|
|
40
|
+
}
|
|
41
|
+
if (node.type === "MetaProperty" &&
|
|
42
|
+
node.meta.name === "import" &&
|
|
43
|
+
node.property.name === "meta") {
|
|
44
|
+
importMetas.add(node);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (node.type !== "MemberExpression" ||
|
|
48
|
+
node.computed ||
|
|
49
|
+
node.object.type !== "MetaProperty" ||
|
|
50
|
+
node.object.meta.name !== "import" ||
|
|
51
|
+
node.object.property.name !== "meta" ||
|
|
52
|
+
node.property.type !== "Identifier" ||
|
|
53
|
+
node.property.name !== "url") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
metaURLs.set(node.object, sourceRange(node, path));
|
|
57
|
+
});
|
|
58
|
+
for (const meta of importMetas) {
|
|
59
|
+
if (!metaURLs.has(meta)) {
|
|
60
|
+
failInline("Only import.meta.url is supported", path, "transform");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return [...metaURLs.values()];
|
|
64
|
+
}
|
|
65
|
+
function importType(node, path) {
|
|
66
|
+
if (node.importKind === "typeof") {
|
|
67
|
+
failInline("Typeof imports are not supported", path, "transform");
|
|
68
|
+
}
|
|
69
|
+
return node.importKind === "type" ? "type" : "value";
|
|
70
|
+
}
|
|
71
|
+
function validateImport(node, path) {
|
|
72
|
+
if (node.attributes && node.attributes.length > 0) {
|
|
73
|
+
failInline("Import attributes are not supported", path, "transform");
|
|
74
|
+
}
|
|
75
|
+
if (node.module || node.phase) {
|
|
76
|
+
failInline("Source-phase and deferred imports are not supported", path, "transform");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function externalImports(node, path) {
|
|
80
|
+
const source = node.source.value;
|
|
81
|
+
if (node.specifiers.length === 0) {
|
|
82
|
+
return [{ kind: "side-effect", path, source }];
|
|
83
|
+
}
|
|
84
|
+
const declarationType = importType(node, path);
|
|
85
|
+
return node.specifiers.map((specifier) => {
|
|
86
|
+
if (specifier.type === "ImportDefaultSpecifier") {
|
|
87
|
+
return {
|
|
88
|
+
kind: "binding",
|
|
89
|
+
imported: "default",
|
|
90
|
+
local: specifier.local.name,
|
|
91
|
+
path,
|
|
92
|
+
source,
|
|
93
|
+
typeOnly: declarationType === "type"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
97
|
+
return {
|
|
98
|
+
kind: "binding",
|
|
99
|
+
imported: "*",
|
|
100
|
+
local: specifier.local.name,
|
|
101
|
+
path,
|
|
102
|
+
source,
|
|
103
|
+
typeOnly: declarationType === "type"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (specifier.importKind === "typeof") {
|
|
107
|
+
failInline("Typeof imports are not supported", path, "transform");
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
kind: "binding",
|
|
111
|
+
imported: specifier.imported.type === "Identifier"
|
|
112
|
+
? specifier.imported.name
|
|
113
|
+
: specifier.imported.value,
|
|
114
|
+
local: specifier.local.name,
|
|
115
|
+
path,
|
|
116
|
+
source,
|
|
117
|
+
typeOnly: declarationType === "type" || specifier.importKind === "type"
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function localImport(node, url, path) {
|
|
122
|
+
if (node.importKind === "type" ||
|
|
123
|
+
node.specifiers.length !== 1 ||
|
|
124
|
+
node.specifiers[0]?.type !== "ImportDefaultSpecifier") {
|
|
125
|
+
failInline("Local GLTS imports must be default imports", path, "transform");
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
...sourceRange(node, path),
|
|
129
|
+
local: node.specifiers[0].local.name,
|
|
130
|
+
url
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function parseImports(options, externalSyntax) {
|
|
134
|
+
const ast = parseModule(options.source, options.path);
|
|
135
|
+
const imports = [];
|
|
136
|
+
const externals = [];
|
|
137
|
+
const importRanges = [];
|
|
138
|
+
const firstNode = ast.program.body[0];
|
|
139
|
+
let insertAt = firstNode
|
|
140
|
+
? sourceRange(firstNode, options.path).start
|
|
141
|
+
: options.source.length;
|
|
142
|
+
let bodyStarted = false;
|
|
143
|
+
for (const node of ast.program.body) {
|
|
144
|
+
if (node.type !== "ImportDeclaration") {
|
|
145
|
+
bodyStarted = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const nodeRange = sourceRange(node, options.path);
|
|
149
|
+
importRanges.push(nodeRange);
|
|
150
|
+
if (!bodyStarted) {
|
|
151
|
+
insertAt = nodeRange.end;
|
|
152
|
+
}
|
|
153
|
+
const target = options.resolveImport(node.source.value);
|
|
154
|
+
if (externalSyntax === "validate" || target) {
|
|
155
|
+
validateImport(node, options.path);
|
|
156
|
+
}
|
|
157
|
+
if (target) {
|
|
158
|
+
imports.push(localImport(node, target, options.path));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
externals.push(...externalImports(node, options.path));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { ast, externals, importRanges, imports, insertAt };
|
|
165
|
+
}
|
|
166
|
+
function readDefaultClass(node, path) {
|
|
167
|
+
if (node.declaration.type !== "ClassDeclaration") {
|
|
168
|
+
failInline("Inlined dependencies must default-export a class", path, "transform");
|
|
169
|
+
}
|
|
170
|
+
const exportRange = sourceRange(node, path);
|
|
171
|
+
const classRange = sourceRange(node.declaration, path);
|
|
172
|
+
if (node.declaration.id) {
|
|
173
|
+
return {
|
|
174
|
+
kind: "named",
|
|
175
|
+
classStart: classRange.start,
|
|
176
|
+
exportStart: exportRange.start,
|
|
177
|
+
name: node.declaration.id.name
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
kind: "anonymous",
|
|
182
|
+
classEnd: classRange.end,
|
|
183
|
+
classStart: classRange.start,
|
|
184
|
+
exportStart: exportRange.start
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function validatePreviewNames(names, path) {
|
|
188
|
+
if (names.length > 0 && names.every((name) => previewExportNames.has(name))) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
failInline("Inlined dependencies may only have a default export or named preview exports", path, "transform");
|
|
192
|
+
}
|
|
193
|
+
function readPreviewExport(node, path) {
|
|
194
|
+
if (node.source || node.exportKind === "type") {
|
|
195
|
+
failInline("Inlined dependencies may only have a default export or named preview exports", path, "transform");
|
|
196
|
+
}
|
|
197
|
+
const exportRange = sourceRange(node, path);
|
|
198
|
+
if (node.declaration) {
|
|
199
|
+
if (node.declaration.type !== "VariableDeclaration") {
|
|
200
|
+
failInline("Inlined preview exports must be variable declarations", path, "transform");
|
|
201
|
+
}
|
|
202
|
+
const names = node.declaration.declarations.map((declaration) => {
|
|
203
|
+
if (declaration.id.type !== "Identifier") {
|
|
204
|
+
failInline("Inlined preview exports must use identifier bindings", path, "transform");
|
|
205
|
+
}
|
|
206
|
+
return declaration.id.name;
|
|
207
|
+
});
|
|
208
|
+
validatePreviewNames(names, path);
|
|
209
|
+
const declarationRange = sourceRange(node.declaration, path);
|
|
210
|
+
return {
|
|
211
|
+
start: exportRange.start,
|
|
212
|
+
end: declarationRange.start
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const names = node.specifiers.map((specifier) => {
|
|
216
|
+
if (specifier.type !== "ExportSpecifier" || specifier.exportKind === "type") {
|
|
217
|
+
failInline("Inlined preview exports must be runtime value exports", path, "transform");
|
|
218
|
+
}
|
|
219
|
+
return specifier.exported.type === "Identifier"
|
|
220
|
+
? specifier.exported.name
|
|
221
|
+
: specifier.exported.value;
|
|
222
|
+
});
|
|
223
|
+
validatePreviewNames(names, path);
|
|
224
|
+
return exportRange;
|
|
225
|
+
}
|
|
226
|
+
export function analyzeEntryModule(options) {
|
|
227
|
+
const parsed = parseImports(options, "preserve");
|
|
228
|
+
for (const node of parsed.ast.program.body) {
|
|
229
|
+
if ((node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") &&
|
|
230
|
+
node.source &&
|
|
231
|
+
options.resolveImport(node.source.value)) {
|
|
232
|
+
failInline("Local GLTS re-exports are not supported", options.path, "transform");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
externals: parsed.externals,
|
|
237
|
+
imports: parsed.imports,
|
|
238
|
+
insertAt: parsed.insertAt,
|
|
239
|
+
source: options.source
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export function analyzeDependencyModule(options) {
|
|
243
|
+
const parsed = parseImports(options, "validate");
|
|
244
|
+
const previewRemovals = [];
|
|
245
|
+
let defaultClass;
|
|
246
|
+
for (const node of parsed.ast.program.body) {
|
|
247
|
+
if (node.type === "ImportDeclaration") {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (node.type === "TSImportEqualsDeclaration") {
|
|
251
|
+
failInline("TypeScript import-equals declarations are not supported", options.path, "transform");
|
|
252
|
+
}
|
|
253
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
254
|
+
if (defaultClass) {
|
|
255
|
+
failInline("Inlined dependency has more than one default export", options.path, "transform");
|
|
256
|
+
}
|
|
257
|
+
defaultClass = readDefaultClass(node, options.path);
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
261
|
+
previewRemovals.push(readPreviewExport(node, options.path));
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (node.type === "ExportAllDeclaration" ||
|
|
265
|
+
node.type === "TSExportAssignment" ||
|
|
266
|
+
node.type === "TSNamespaceExportDeclaration") {
|
|
267
|
+
failInline("Inlined dependencies may only have a default export", options.path, "transform");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (!defaultClass) {
|
|
271
|
+
failInline("Inlined dependency must have a default export", options.path, "transform");
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
defaultClass,
|
|
275
|
+
externals: parsed.externals,
|
|
276
|
+
imports: parsed.imports,
|
|
277
|
+
metaURLs: metaURLRanges(parsed.ast, options.path),
|
|
278
|
+
metaURL: options.metaURL,
|
|
279
|
+
path: options.path,
|
|
280
|
+
removals: [...parsed.importRanges, ...previewRemovals],
|
|
281
|
+
source: options.source,
|
|
282
|
+
url: options.url
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export function validateInlineSyntax(source) {
|
|
286
|
+
parseModule(source, "<inline output>");
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=inline-analysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-analysis.js","sourceRoot":"","sources":["../src/inline-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAqC,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA+ExC,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC;IACtD,eAAe;IACf,iBAAiB;CAClB,CAAC,CAAC;AAEH,MAAM,UAAU,UAAU,CACxB,OAAe,EACf,IAAY,EACZ,KAA8B,EAC9B,cAAiC,EAAE,EACnC,KAAe;IAEf,MAAM,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,WAAW,CAAC,IAAU,EAAE,IAAY;IAC3C,IAAI,OAAO,IAAI,CAAC,KAAK,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
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../src/inline.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../src/inline.ts"],"names":[],"mappings":"AAgRA,sFAAsF;AACtF,wBAAgB,MAAM,CACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACtC,MAAM,CAwFR"}
|
package/dist/inline.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import { parse } from "@babel/parser";
|
|
2
|
-
import { traverseFast } from "@babel/types";
|
|
3
1
|
import MagicString from "magic-string";
|
|
4
|
-
import {
|
|
2
|
+
import { analyzeDependencyModule, analyzeEntryModule, failInline as fail, validateInlineSyntax } from "./inline-analysis.js";
|
|
5
3
|
const entryURL = new URL("glts://inline/entry.glts");
|
|
6
|
-
function fail(message, path, phase, importChain = [], cause) {
|
|
7
|
-
throw new GLTSError(message, { url: path, phase, importChain }, cause);
|
|
8
|
-
}
|
|
9
|
-
function range(node, path) {
|
|
10
|
-
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
11
|
-
fail("Parser returned a node without a source range", path, "transform");
|
|
12
|
-
}
|
|
13
|
-
return { start: node.start, end: node.end };
|
|
14
|
-
}
|
|
15
4
|
function isBare(specifier) {
|
|
16
5
|
return (!specifier.startsWith(".") &&
|
|
17
6
|
!specifier.startsWith("/") &&
|
|
@@ -52,117 +41,6 @@ function sourceMap(files) {
|
|
|
52
41
|
}
|
|
53
42
|
return sources;
|
|
54
43
|
}
|
|
55
|
-
function parseModule(source, path) {
|
|
56
|
-
try {
|
|
57
|
-
return parse(source, {
|
|
58
|
-
plugins: ["decorators-legacy", "deferredImportEvaluation", "sourcePhaseImports", "typescript"],
|
|
59
|
-
sourceFilename: path,
|
|
60
|
-
sourceType: "module"
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
fail("Unable to parse TypeScript source", path, "transform", [], error);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function moduleSyntax(ast, path) {
|
|
68
|
-
const importMetas = new Set();
|
|
69
|
-
const metaURLs = new Map();
|
|
70
|
-
traverseFast(ast, (node) => {
|
|
71
|
-
if (node.type === "ImportExpression") {
|
|
72
|
-
fail("Dynamic imports are not supported", path, "transform");
|
|
73
|
-
}
|
|
74
|
-
if (node.type === "MetaProperty" &&
|
|
75
|
-
node.meta.name === "import" &&
|
|
76
|
-
node.property.name === "meta") {
|
|
77
|
-
importMetas.add(node);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (node.type !== "MemberExpression" ||
|
|
81
|
-
node.computed ||
|
|
82
|
-
node.object.type !== "MetaProperty" ||
|
|
83
|
-
node.object.meta.name !== "import" ||
|
|
84
|
-
node.object.property.name !== "meta" ||
|
|
85
|
-
node.property.type !== "Identifier" ||
|
|
86
|
-
node.property.name !== "url") {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
metaURLs.set(node.object, range(node, path));
|
|
90
|
-
});
|
|
91
|
-
for (const meta of importMetas) {
|
|
92
|
-
if (!metaURLs.has(meta)) {
|
|
93
|
-
fail("Only import.meta.url is supported", path, "transform");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return [...metaURLs.values()];
|
|
97
|
-
}
|
|
98
|
-
function importType(node, path) {
|
|
99
|
-
if (node.importKind === "typeof") {
|
|
100
|
-
fail("Typeof imports are not supported", path, "transform");
|
|
101
|
-
}
|
|
102
|
-
return node.importKind === "type" ? "type" : "value";
|
|
103
|
-
}
|
|
104
|
-
function checkImport(node, path) {
|
|
105
|
-
if (node.attributes && node.attributes.length > 0) {
|
|
106
|
-
fail("Import attributes are not supported", path, "transform");
|
|
107
|
-
}
|
|
108
|
-
if (node.module || node.phase) {
|
|
109
|
-
fail("Source-phase and deferred imports are not supported", path, "transform");
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function externalImports(node, path) {
|
|
113
|
-
const source = node.source.value;
|
|
114
|
-
if (node.specifiers.length === 0) {
|
|
115
|
-
return [{ kind: "side-effect", path, source }];
|
|
116
|
-
}
|
|
117
|
-
const declarationType = importType(node, path);
|
|
118
|
-
return node.specifiers.map((specifier) => {
|
|
119
|
-
if (specifier.type === "ImportDefaultSpecifier") {
|
|
120
|
-
return {
|
|
121
|
-
kind: "binding",
|
|
122
|
-
imported: "default",
|
|
123
|
-
local: specifier.local.name,
|
|
124
|
-
path,
|
|
125
|
-
source,
|
|
126
|
-
typeOnly: declarationType === "type"
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
130
|
-
return {
|
|
131
|
-
kind: "binding",
|
|
132
|
-
imported: "*",
|
|
133
|
-
local: specifier.local.name,
|
|
134
|
-
path,
|
|
135
|
-
source,
|
|
136
|
-
typeOnly: declarationType === "type"
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (specifier.importKind === "typeof") {
|
|
140
|
-
fail("Typeof imports are not supported", path, "transform");
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
kind: "binding",
|
|
144
|
-
imported: specifier.imported.type === "Identifier"
|
|
145
|
-
? specifier.imported.name
|
|
146
|
-
: specifier.imported.value,
|
|
147
|
-
local: specifier.local.name,
|
|
148
|
-
path,
|
|
149
|
-
source,
|
|
150
|
-
typeOnly: declarationType === "type" || specifier.importKind === "type"
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function localImport(node, url, path) {
|
|
155
|
-
if (node.importKind === "type" ||
|
|
156
|
-
node.specifiers.length !== 1 ||
|
|
157
|
-
node.specifiers[0]?.type !== "ImportDefaultSpecifier") {
|
|
158
|
-
fail("Local GLTS imports must be default imports", path, "transform");
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
...range(node, path),
|
|
162
|
-
local: node.specifiers[0].local.name,
|
|
163
|
-
url
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
44
|
function resolveImport(specifier, importer, path, sources, root) {
|
|
167
45
|
if (isBare(specifier)) {
|
|
168
46
|
return undefined;
|
|
@@ -188,97 +66,6 @@ function resolveImport(specifier, importer, path, sources, root) {
|
|
|
188
66
|
}
|
|
189
67
|
return undefined;
|
|
190
68
|
}
|
|
191
|
-
function defaultClass(node, path) {
|
|
192
|
-
if (node.declaration.type !== "ClassDeclaration") {
|
|
193
|
-
fail("Inlined dependencies must default-export a class", path, "transform");
|
|
194
|
-
}
|
|
195
|
-
const exportRange = range(node, path);
|
|
196
|
-
const classRange = range(node.declaration, path);
|
|
197
|
-
if (node.declaration.id) {
|
|
198
|
-
return {
|
|
199
|
-
kind: "named",
|
|
200
|
-
classStart: classRange.start,
|
|
201
|
-
exportStart: exportRange.start,
|
|
202
|
-
name: node.declaration.id.name
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
kind: "anonymous",
|
|
207
|
-
classEnd: classRange.end,
|
|
208
|
-
classStart: classRange.start,
|
|
209
|
-
exportStart: exportRange.start
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function readFile(source, url, path, metaURL, sources, root) {
|
|
213
|
-
const ast = parseModule(source, path);
|
|
214
|
-
const imports = [];
|
|
215
|
-
const externals = [];
|
|
216
|
-
const importRanges = [];
|
|
217
|
-
let exported;
|
|
218
|
-
const firstNode = ast.program.body[0];
|
|
219
|
-
let insertAt = firstNode ? range(firstNode, path).start : source.length;
|
|
220
|
-
let bodyStarted = false;
|
|
221
|
-
for (const node of ast.program.body) {
|
|
222
|
-
if (node.type === "ImportDeclaration") {
|
|
223
|
-
const nodeRange = range(node, path);
|
|
224
|
-
importRanges.push(nodeRange);
|
|
225
|
-
if (!bodyStarted) {
|
|
226
|
-
insertAt = nodeRange.end;
|
|
227
|
-
}
|
|
228
|
-
const target = resolveImport(node.source.value, url, path, sources, root);
|
|
229
|
-
if (!root || target) {
|
|
230
|
-
checkImport(node, path);
|
|
231
|
-
}
|
|
232
|
-
if (target) {
|
|
233
|
-
imports.push(localImport(node, target, path));
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
externals.push(...externalImports(node, path));
|
|
237
|
-
}
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
bodyStarted = true;
|
|
241
|
-
if (!root && node.type === "TSImportEqualsDeclaration") {
|
|
242
|
-
fail("TypeScript import-equals declarations are not supported", path, "transform");
|
|
243
|
-
}
|
|
244
|
-
if (root) {
|
|
245
|
-
if ((node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") &&
|
|
246
|
-
node.source &&
|
|
247
|
-
resolveImport(node.source.value, url, path, sources, root)) {
|
|
248
|
-
fail("Local GLTS re-exports are not supported", path, "transform");
|
|
249
|
-
}
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
if (node.type === "ExportDefaultDeclaration") {
|
|
253
|
-
if (exported) {
|
|
254
|
-
fail("Inlined dependency has more than one default export", path, "transform");
|
|
255
|
-
}
|
|
256
|
-
exported = defaultClass(node, path);
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
if (node.type === "ExportNamedDeclaration" ||
|
|
260
|
-
node.type === "ExportAllDeclaration" ||
|
|
261
|
-
node.type === "TSExportAssignment" ||
|
|
262
|
-
node.type === "TSNamespaceExportDeclaration") {
|
|
263
|
-
fail("Inlined dependencies may only have a default export", path, "transform");
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
if (!root && !exported) {
|
|
267
|
-
fail("Inlined dependency must have a default export", path, "transform");
|
|
268
|
-
}
|
|
269
|
-
return {
|
|
270
|
-
...(exported ? { defaultClass: exported } : {}),
|
|
271
|
-
externals,
|
|
272
|
-
importRanges,
|
|
273
|
-
imports,
|
|
274
|
-
insertAt,
|
|
275
|
-
metaURLs: root ? [] : moduleSyntax(ast, path),
|
|
276
|
-
metaURL,
|
|
277
|
-
path,
|
|
278
|
-
source,
|
|
279
|
-
url
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
69
|
function sameImport(left, right) {
|
|
283
70
|
return (left.imported === right.imported &&
|
|
284
71
|
left.source === right.source &&
|
|
@@ -360,12 +147,9 @@ function sourceURL(metaURL) {
|
|
|
360
147
|
}
|
|
361
148
|
function renderFile(file, name, names, wrapperGroup) {
|
|
362
149
|
const exported = file.defaultClass;
|
|
363
|
-
if (!exported) {
|
|
364
|
-
fail("Inlined dependency has no default class", file.path, "transform");
|
|
365
|
-
}
|
|
366
150
|
const rewritten = new MagicString(file.source);
|
|
367
|
-
for (const
|
|
368
|
-
rewritten.remove(
|
|
151
|
+
for (const removal of file.removals) {
|
|
152
|
+
rewritten.remove(removal.start, removal.end);
|
|
369
153
|
}
|
|
370
154
|
for (const metaURL of file.metaURLs) {
|
|
371
155
|
rewritten.overwrite(metaURL.start, metaURL.end, sourceURL(file.metaURL));
|
|
@@ -406,13 +190,14 @@ function prefix(files) {
|
|
|
406
190
|
}
|
|
407
191
|
return value;
|
|
408
192
|
}
|
|
409
|
-
function validate(source) {
|
|
410
|
-
parseModule(source, "<inline output>");
|
|
411
|
-
}
|
|
412
193
|
/** Combines a root GLTS module and its in-memory dependencies into TypeScript ESM. */
|
|
413
194
|
export function inline(source, files) {
|
|
414
195
|
const sources = sourceMap(files);
|
|
415
|
-
const root =
|
|
196
|
+
const root = analyzeEntryModule({
|
|
197
|
+
path: "<entry>",
|
|
198
|
+
resolveImport: (specifier) => resolveImport(specifier, entryURL, "<entry>", sources, true),
|
|
199
|
+
source
|
|
200
|
+
});
|
|
416
201
|
if (root.imports.length === 0) {
|
|
417
202
|
return source;
|
|
418
203
|
}
|
|
@@ -429,7 +214,13 @@ export function inline(source, files) {
|
|
|
429
214
|
if (!input) {
|
|
430
215
|
fail(`Missing inline source for ${displayURL(url)}`, displayURL(url), "resolve");
|
|
431
216
|
}
|
|
432
|
-
const file =
|
|
217
|
+
const file = analyzeDependencyModule({
|
|
218
|
+
metaURL: input.metaURL,
|
|
219
|
+
path: input.path,
|
|
220
|
+
resolveImport: (specifier) => resolveImport(specifier, input.url, input.path, sources, false),
|
|
221
|
+
source: input.source,
|
|
222
|
+
url: input.url
|
|
223
|
+
});
|
|
433
224
|
const nextChain = [...chain, url.href];
|
|
434
225
|
for (const dependency of file.imports) {
|
|
435
226
|
load(dependency.url, nextChain);
|
|
@@ -468,7 +259,7 @@ export function inline(source, files) {
|
|
|
468
259
|
}
|
|
469
260
|
rewritten.appendLeft(root.insertAt, `\n\n${addition}`);
|
|
470
261
|
const output = rewritten.toString();
|
|
471
|
-
|
|
262
|
+
validateInlineSyntax(output);
|
|
472
263
|
return output;
|
|
473
264
|
}
|
|
474
265
|
//# sourceMappingURL=inline.js.map
|