50 lines
1.3 KiB
HTML
50 lines
1.3 KiB
HTML
<script type="module" src="test_receiver.mjs"></script>
|
|
|
|
<!--
|
|
<script type="module">
|
|
import r1 from "./test_rand.mjs?1";
|
|
import r2 from "./test_rand.mjs?2";
|
|
import r3 from "./test_rand.mjs?3";
|
|
import r4 from "./test_rand.mjs?4";
|
|
|
|
console.log(r1, r2, r3, r4);
|
|
|
|
</script>-->
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/typescript/4.5.4/typescript.min.js"></script>
|
|
<script type="module">
|
|
|
|
// TypeScript source code
|
|
const source = `
|
|
export const num: number = 42;
|
|
export function greet() {
|
|
console.log('Hello, world!');
|
|
}
|
|
`;
|
|
|
|
// Transpile the TypeScript code to JavaScript
|
|
const result = ts.transpileModule(source, {
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.ESNext,
|
|
target: ts.ScriptTarget.ESNext
|
|
}
|
|
});
|
|
|
|
// Parse the AST of the TypeScript source code
|
|
const sourceFile = ts.createSourceFile('module.ts', source, ts.ScriptTarget.ESNext, true);
|
|
|
|
// Function to inspect the AST and find export declarations
|
|
function findExports(node) {
|
|
if (ts.isExportDeclaration(node) || ts.isExportAssignment(node)) {
|
|
console.log('Export found:', node);
|
|
}
|
|
ts.forEachChild(node, findExports);
|
|
}
|
|
|
|
// Traverse the AST
|
|
//findExports(sourceFile);
|
|
|
|
console.log(sourceFile);
|
|
// Output: export const num = 42; export function greet() { console.log('Hello, world!'); }
|
|
|
|
</script> |