xbintsc 0.3.4 → 0.3.5
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/src/codegen/generator/calls/invocation.js +9 -0
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/context.d.ts +15 -1
- package/dist/src/codegen/generator/context.js +29 -4
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/tests/ast/factory.test.d.ts +1 -0
- package/dist/tests/ast/factory.test.js +35 -0
- package/dist/tests/ast/factory.test.js.map +1 -0
- package/dist/tests/ast/visitor.test.d.ts +1 -0
- package/dist/tests/ast/visitor.test.js +53 -0
- package/dist/tests/ast/visitor.test.js.map +1 -0
- package/dist/tests/cli/main.test.js +109 -9
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/closures.test.d.ts +1 -0
- package/dist/tests/codegen/closures.test.js +32 -0
- package/dist/tests/codegen/closures.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.d.ts +1 -0
- package/dist/tests/codegen/expressions.test.js +149 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -0
- package/dist/tests/codegen/llvm.test.js +14 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/codegen/values.test.d.ts +1 -0
- package/dist/tests/codegen/values.test.js +48 -0
- package/dist/tests/codegen/values.test.js.map +1 -0
- package/dist/tests/diagnostics/diagnostic.test.d.ts +1 -0
- package/dist/tests/diagnostics/diagnostic.test.js +117 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.d.ts +1 -0
- package/dist/tests/diagnostics/source.test.js +58 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -0
- package/dist/tests/driver/modules.test.d.ts +1 -0
- package/dist/tests/driver/modules.test.js +140 -0
- package/dist/tests/driver/modules.test.js.map +1 -0
- package/dist/tests/driver/paths.test.js +17 -1
- package/dist/tests/driver/paths.test.js.map +1 -1
- package/dist/tests/driver/runtime-lib.test.d.ts +1 -0
- package/dist/tests/driver/runtime-lib.test.js +19 -0
- package/dist/tests/driver/runtime-lib.test.js.map +1 -0
- package/dist/tests/driver/toolchain-provider.test.js +91 -0
- package/dist/tests/driver/toolchain-provider.test.js.map +1 -1
- package/dist/tests/e2e/compile-node.test.js +11 -0
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/extensions/node.test.d.ts +1 -0
- package/dist/tests/extensions/node.test.js +32 -0
- package/dist/tests/extensions/node.test.js.map +1 -0
- package/dist/tests/lexer/identifiers.test.d.ts +1 -0
- package/dist/tests/lexer/identifiers.test.js +13 -0
- package/dist/tests/lexer/identifiers.test.js.map +1 -0
- package/dist/tests/lexer/numbers.test.d.ts +1 -0
- package/dist/tests/lexer/numbers.test.js +23 -0
- package/dist/tests/lexer/numbers.test.js.map +1 -0
- package/dist/tests/lexer/strings.test.d.ts +1 -0
- package/dist/tests/lexer/strings.test.js +72 -0
- package/dist/tests/lexer/strings.test.js.map +1 -0
- package/dist/tests/parser/declarations.test.d.ts +1 -0
- package/dist/tests/parser/declarations.test.js +70 -0
- package/dist/tests/parser/declarations.test.js.map +1 -0
- package/dist/tests/parser/expressions.test.d.ts +1 -0
- package/dist/tests/parser/expressions.test.js +47 -0
- package/dist/tests/parser/expressions.test.js.map +1 -0
- package/dist/tests/parser/helpers.test.d.ts +1 -0
- package/dist/tests/parser/helpers.test.js +58 -0
- package/dist/tests/parser/helpers.test.js.map +1 -0
- package/dist/tests/parser/literals.test.d.ts +1 -0
- package/dist/tests/parser/literals.test.js +70 -0
- package/dist/tests/parser/literals.test.js.map +1 -0
- package/dist/tests/parser/module-syntax.test.d.ts +1 -0
- package/dist/tests/parser/module-syntax.test.js +91 -0
- package/dist/tests/parser/module-syntax.test.js.map +1 -0
- package/dist/tests/parser/statements.test.d.ts +1 -0
- package/dist/tests/parser/statements.test.js +85 -0
- package/dist/tests/parser/statements.test.js.map +1 -0
- package/dist/tests/parser/type-members.test.d.ts +1 -0
- package/dist/tests/parser/type-members.test.js +86 -0
- package/dist/tests/parser/type-members.test.js.map +1 -0
- package/dist/tests/parser/types.test.d.ts +1 -0
- package/dist/tests/parser/types.test.js +143 -0
- package/dist/tests/parser/types.test.js.map +1 -0
- package/package.json +1 -1
- package/src/codegen/generator/calls/invocation.ts +8 -0
- package/src/codegen/generator/context.ts +30 -4
package/package.json
CHANGED
|
@@ -206,6 +206,14 @@ export const invocationCallMethods: InvocationCallMethods = {
|
|
|
206
206
|
return result;
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
+
// Modules with no namespace dispatcher (`fs`, `child_process`, ...): lower
|
|
210
|
+
// `import fs from "node:fs"; fs.readFileSync(...)` through the module's
|
|
211
|
+
// named exports, exactly like a named import of `readFileSync`.
|
|
212
|
+
const moduleExports = this.moduleExportsOfSymbol(targetSymbol);
|
|
213
|
+
if (moduleExports) {
|
|
214
|
+
const exported = moduleExports[method];
|
|
215
|
+
if (exported) return this.emitModuleExport(node, exported);
|
|
216
|
+
}
|
|
209
217
|
}
|
|
210
218
|
|
|
211
219
|
void BUILTIN_METHODS;
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
BuiltinFunction,
|
|
16
16
|
ExtensionModule,
|
|
17
17
|
ModuleExport,
|
|
18
|
+
ModuleExports,
|
|
18
19
|
} from "../../extensions/registry.js";
|
|
19
20
|
import type { CodegenOptions, FunctionState } from "./state.js";
|
|
20
21
|
import { escapeBytes, isErrorFamily, kindName, utf8Bytes } from "./tables.js";
|
|
@@ -29,6 +30,13 @@ export class GeneratorContext {
|
|
|
29
30
|
readonly importExports = new Map<number, ModuleExport>();
|
|
30
31
|
/** Imported symbol id -> the namespace it aliases (e.g. `path`). */
|
|
31
32
|
readonly importNamespaces = new Map<number, string>();
|
|
33
|
+
/**
|
|
34
|
+
* Imported symbol id -> the named exports of the module it aliases, for
|
|
35
|
+
* modules that do not expose a runtime namespace dispatcher (`fs`,
|
|
36
|
+
* `child_process`, `crypto`, ...). Lets `import fs from "node:fs"` lower
|
|
37
|
+
* `fs.readFileSync(...)` straight to the module's runtime symbol.
|
|
38
|
+
*/
|
|
39
|
+
readonly importModuleExports = new Map<number, ModuleExports>();
|
|
32
40
|
readonly globals: string[] = [];
|
|
33
41
|
readonly functions: string[] = [];
|
|
34
42
|
readonly strings = new Map<string, { label: string; length: number }>();
|
|
@@ -61,9 +69,9 @@ export class GeneratorContext {
|
|
|
61
69
|
if (!module) continue;
|
|
62
70
|
const clause = declaration.importClause;
|
|
63
71
|
if (!clause) continue;
|
|
64
|
-
if (clause.name
|
|
72
|
+
if (clause.name) {
|
|
65
73
|
const symbol = this.binding.symbolOfDeclaration.get(clause.name);
|
|
66
|
-
if (symbol) this.
|
|
74
|
+
if (symbol) this.bindModuleAlias(symbol, module);
|
|
67
75
|
}
|
|
68
76
|
const bindings = clause.namedBindings;
|
|
69
77
|
if (bindings && bindings.kind === SyntaxKind.NamedImports) {
|
|
@@ -73,19 +81,37 @@ export class GeneratorContext {
|
|
|
73
81
|
const symbol = this.binding.symbolOfDeclaration.get(specifier.name);
|
|
74
82
|
if (symbol && exported) this.importExports.set(symbol.id, exported);
|
|
75
83
|
}
|
|
76
|
-
} else if (bindings && bindings.kind === SyntaxKind.NamespaceImport
|
|
84
|
+
} else if (bindings && bindings.kind === SyntaxKind.NamespaceImport) {
|
|
77
85
|
const symbol = this.binding.symbolOfDeclaration.get(bindings.name);
|
|
78
|
-
if (symbol) this.
|
|
86
|
+
if (symbol) this.bindModuleAlias(symbol, module);
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Bind a default/namespace import to either the module's runtime namespace
|
|
93
|
+
* dispatcher (when it has one) or its named exports (when it does not).
|
|
94
|
+
*/
|
|
95
|
+
private bindModuleAlias(symbol: SymbolInfo, module: ExtensionModule): void {
|
|
96
|
+
if (module.namespace) {
|
|
97
|
+
this.importNamespaces.set(symbol.id, module.namespace);
|
|
98
|
+
} else if (module.exports) {
|
|
99
|
+
this.importModuleExports.set(symbol.id, module.exports);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
83
103
|
/** Namespace name an imported alias refers to, if any. */
|
|
84
104
|
namespaceOfSymbol(symbol: SymbolInfo | undefined): string | undefined {
|
|
85
105
|
if (!symbol || symbol.kind !== SymbolKind.Import) return undefined;
|
|
86
106
|
return this.importNamespaces.get(symbol.id);
|
|
87
107
|
}
|
|
88
108
|
|
|
109
|
+
/** Named exports a default/namespace import aliases, if any. */
|
|
110
|
+
moduleExportsOfSymbol(symbol: SymbolInfo | undefined): ModuleExports | undefined {
|
|
111
|
+
if (!symbol || symbol.kind !== SymbolKind.Import) return undefined;
|
|
112
|
+
return this.importModuleExports.get(symbol.id);
|
|
113
|
+
}
|
|
114
|
+
|
|
89
115
|
// -- emission primitives -------------------------------------------------
|
|
90
116
|
|
|
91
117
|
emit(line: string): void {
|