Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from broofa/master
keep script directives at top of file, fixes #185
- Loading branch information
Showing
9 changed files
with
148 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ParseResult } from '@babel/parser'; | ||
import traverse, { NodePath } from '@babel/traverse'; | ||
import { | ||
Directive, | ||
File, | ||
ImportDeclaration, | ||
isTSModuleDeclaration, | ||
} from '@babel/types'; | ||
|
||
export function extractASTNodes(ast: ParseResult<File>) { | ||
const importNodes: ImportDeclaration[] = []; | ||
const directives: Directive[] = []; | ||
traverse(ast, { | ||
Directive({ node }) { | ||
directives.push(node); | ||
|
||
// Trailing comments probably shouldn't be attached to the directive | ||
node.trailingComments = null; | ||
}, | ||
|
||
ImportDeclaration(path: NodePath<ImportDeclaration>) { | ||
const tsModuleParent = path.findParent((p) => | ||
isTSModuleDeclaration(p), | ||
); | ||
if (!tsModuleParent) { | ||
importNodes.push(path.node); | ||
} | ||
}, | ||
}); | ||
return { importNodes, directives }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
'use client'; | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
// Comment | ||
function add(a:number,b:number) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
'use client'; | ||
|
||
// comment after directives | ||
import otherthing from "@core/otherthing"; | ||
import abc from "@core/abc"; | ||
|
||
// Comment | ||
|
||
function add(a:number,b:number) { | ||
return a + b; | ||
} |