@@ -23,8 +23,10 @@ export const parseImportsSync = (code, { resolveFrom } = {}) => {
2323 for ( let {
2424 d : dynamicImportStartIndex ,
2525 ss : statementStartIndex ,
26+ se : statementEndIndex ,
2627 s : moduleSpecifierStartIndex ,
2728 e : moduleSpecifierEndIndexExclusive ,
29+ a : metaStartIndex ,
2830 } of imports ) {
2931 const isImportMeta = dynamicImportStartIndex === - 2
3032 if ( isImportMeta ) {
@@ -69,7 +71,24 @@ export const parseImportsSync = (code, { resolveFrom } = {}) => {
6971 importClause = parseImportClause ( importClauseString )
7072 }
7173
72- yield {
74+ let meta
75+ if ( metaStartIndex > - 1 ) {
76+ let metaString = code . slice ( metaStartIndex , statementEndIndex ) . trim ( )
77+ if ( isDynamicImport ) {
78+ metaString = metaString . slice ( 0 , - 1 )
79+ meta = runExpression ( metaString )
80+ } else {
81+ const metaName = code
82+ . slice ( moduleSpecifierEndIndexExclusive , metaStartIndex )
83+ . trim ( )
84+ if ( metaName ) {
85+ metaString = `{${ metaName } :${ metaString } }`
86+ }
87+ meta = runExpression ( metaString )
88+ }
89+ }
90+
91+ const result = {
7392 startIndex : statementStartIndex ,
7493 // Include the closing parenthesis for dynamic import
7594 endIndex : isDynamicImport
@@ -79,7 +98,17 @@ export const parseImportsSync = (code, { resolveFrom } = {}) => {
7998 moduleSpecifier,
8099 importClause,
81100 }
101+
102+ if ( meta ) {
103+ result . meta = meta
104+ }
105+
106+ yield result
82107 }
83108 } ,
84109 }
85110}
111+
112+ function runExpression ( code ) {
113+ return new Function ( `return ${ code } ` ) ( )
114+ }
0 commit comments