Skip to content

Commit ca5305d

Browse files
committed
extract module context with related import
1 parent 1b7e94c commit ca5305d

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

source-view/transcriber/svelte-transcriber.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class SvelteTranscriber extends Transcriber {
2222
function ExtractModuleContext(this: SvelteTranscriber & ISvelteTranscriber) {
2323
const statements = this.m_Path
2424
.get("body")
25-
.filter(each => !each.isExportDefaultDeclaration() && !each.isImportDeclaration() && !IsLocalContext(each))
25+
.filter(each => !each.isExportDefaultDeclaration() && !IsLocalContext(each))
2626
.map(each => each.node);
2727
if (statements.length === 0) {
2828
return "";

src/transcriber/svelte-transcriber.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class SvelteTranscriber extends Transcriber
2929
<SvelteTranscriber /> + function ExtractModuleContext(this: SvelteTranscriber & ISvelteTranscriber)
3030
{
3131
const statements = this.m_Path.get("body")
32-
.filter(each => !each.isExportDefaultDeclaration() && !each.isImportDeclaration() && !IsLocalContext(each))
32+
.filter(each => !each.isExportDefaultDeclaration() && !IsLocalContext(each))
3333
.map(each => each.node);
3434

3535
if (statements.length === 0)

test/section/__snapshots__/script-section.test.ts.snap

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export function stopAll() {
1414

1515
exports[`module context extract module context: module context is empty 1`] = `""`;
1616

17+
exports[`module context extract module context: with import 1`] = `
18+
"import sum from \\"./sum.js\\";
19+
console.log(sum());"
20+
`;
21+
1722
exports[`translate props get props on demand 1`] = `
1823
"export let answer = 42;
1924
export let question;"

test/section/script-section.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ describe("module context", () =>
178178

179179
SnapshotTestModuleContext(code);
180180
})
181+
182+
test("extract module context: with import", () =>
183+
{
184+
const code = `
185+
import sum from "./sum.js";
186+
import greeting from "./greeting.js";
187+
188+
console.log(sum());
189+
190+
export default function AudioPlayer()
191+
{
192+
console.log(greeting());
193+
}
194+
`;
195+
196+
SnapshotTestModuleContext(code);
197+
198+
})
181199
})
182200

183201
function SnapshotTest(code: string)

0 commit comments

Comments
 (0)