Skip to content

Commit

Permalink
extract module context with related import
Browse files Browse the repository at this point in the history
  • Loading branch information
mistlog committed Feb 19, 2020
1 parent 1b7e94c commit ca5305d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source-view/transcriber/svelte-transcriber.md
Expand Up @@ -22,7 +22,7 @@ export class SvelteTranscriber extends Transcriber {
function ExtractModuleContext(this: SvelteTranscriber & ISvelteTranscriber) {
const statements = this.m_Path
.get("body")
.filter(each => !each.isExportDefaultDeclaration() && !each.isImportDeclaration() && !IsLocalContext(each))
.filter(each => !each.isExportDefaultDeclaration() && !IsLocalContext(each))
.map(each => each.node);
if (statements.length === 0) {
return "";
Expand Down
2 changes: 1 addition & 1 deletion src/transcriber/svelte-transcriber.tsx
Expand Up @@ -29,7 +29,7 @@ export class SvelteTranscriber extends Transcriber
<SvelteTranscriber /> + function ExtractModuleContext(this: SvelteTranscriber & ISvelteTranscriber)
{
const statements = this.m_Path.get("body")
.filter(each => !each.isExportDefaultDeclaration() && !each.isImportDeclaration() && !IsLocalContext(each))
.filter(each => !each.isExportDefaultDeclaration() && !IsLocalContext(each))
.map(each => each.node);

if (statements.length === 0)
Expand Down
5 changes: 5 additions & 0 deletions test/section/__snapshots__/script-section.test.ts.snap
Expand Up @@ -14,6 +14,11 @@ export function stopAll() {

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

exports[`module context extract module context: with import 1`] = `
"import sum from \\"./sum.js\\";
console.log(sum());"
`;

exports[`translate props get props on demand 1`] = `
"export let answer = 42;
export let question;"
Expand Down
18 changes: 18 additions & 0 deletions test/section/script-section.test.ts
Expand Up @@ -178,6 +178,24 @@ describe("module context", () =>

SnapshotTestModuleContext(code);
})

test("extract module context: with import", () =>
{
const code = `
import sum from "./sum.js";
import greeting from "./greeting.js";
console.log(sum());
export default function AudioPlayer()
{
console.log(greeting());
}
`;

SnapshotTestModuleContext(code);

})
})

function SnapshotTest(code: string)
Expand Down

0 comments on commit ca5305d

Please sign in to comment.