11import type { PluginVisitorContext , PluginVisitorObject } from '../../../types/config.ts' ;
2- import { getSafeScriptFromArgs , getStringValue , isStringLiteral } from '../../../typescript/ast-nodes.ts' ;
2+ import { getSafeScriptFromArgs , getScriptFromArg , getScriptFromTemplate } from '../../../typescript/ast-nodes.ts' ;
33
44const tags = new Set ( [ '$' , '$sync' ] ) ;
55const methods = new Set ( [ 'execa' , 'execaSync' , 'execaCommand' , 'execaCommandSync' , 'execaNode' , '$sync' ] ) ;
@@ -14,15 +14,10 @@ export function createExecaVisitor(ctx: PluginVisitorContext): PluginVisitorObje
1414 : tag . type === 'CallExpression' && tag . callee . type === 'Identifier'
1515 ? tag . callee . name
1616 : undefined ;
17- if ( tagName === 'execaNode' ) {
18- for ( const q of node . quasi . quasis ) {
19- if ( q . value . raw ) ctx . addScript ( `node ${ q . value . raw } ` ) ;
20- }
21- } else if ( tagName && tags . has ( tagName ) ) {
22- for ( const q of node . quasi . quasis ) {
23- if ( q . value . raw ) ctx . addScript ( q . value . raw ) ;
24- }
25- }
17+ const isNode = tagName === 'execaNode' ;
18+ if ( ! isNode && ! ( tagName && tags . has ( tagName ) ) ) return ;
19+ const script = getScriptFromTemplate ( node . quasi ) ;
20+ if ( script ) ctx . addScript ( isNode ? `node ${ script } ` : script ) ;
2621 } ,
2722 CallExpression ( node ) {
2823 if ( node . callee . type !== 'Identifier' || ! methods . has ( node . callee . name ) ) return ;
@@ -31,10 +26,8 @@ export function createExecaVisitor(ctx: PluginVisitorContext): PluginVisitorObje
3126 const script = getSafeScriptFromArgs ( node . arguments [ 0 ] , node . arguments [ 1 ] ) ;
3227 if ( script ) ctx . addScript ( `node ${ script } ` ) ;
3328 } else if ( fnName . startsWith ( 'execaCommand' ) ) {
34- if ( node . arguments [ 0 ] && isStringLiteral ( node . arguments [ 0 ] ) ) {
35- const val = getStringValue ( node . arguments [ 0 ] ) ;
36- if ( val ) ctx . addScript ( val ) ;
37- }
29+ const script = getScriptFromArg ( node . arguments [ 0 ] ) ;
30+ if ( script ) ctx . addScript ( script ) ;
3831 } else {
3932 const script = getSafeScriptFromArgs ( node . arguments [ 0 ] , node . arguments [ 1 ] ) ;
4033 if ( script ) ctx . addScript ( script ) ;
0 commit comments