mirror of https://github.com/alibaba/ice.git
				
				
				
			fix: compatible with code has import.meta (#6264)
* fix: changelog * fix: test case
This commit is contained in:
		
							parent
							
								
									390a0ce211
								
							
						
					
					
						commit
						a4b851449a
					
				|  | @ -0,0 +1,5 @@ | |||
| --- | ||||
| '@ice/webpack-config': patch | ||||
| --- | ||||
| 
 | ||||
| fix: compatible with code has import.meta | ||||
|  | @ -12,7 +12,8 @@ const transformImport = async (source: string, coreJsPath: string) => { | |||
|   const str = () => s || (s = new MagicString(source)); | ||||
|   const isESM = exports.length > 0 || imports.some((targetImport) => { | ||||
|     const importString = targetImport.n; | ||||
|     return !importString.includes('core-js') && !importString.includes('@swc/helpers'); | ||||
|     // `targetImport.n` get undefined when code has `import.meta.*`.
 | ||||
|     return importString && !importString.includes('core-js') && !importString.includes('@swc/helpers'); | ||||
|   }); | ||||
|   imports.forEach((targetImport) => { | ||||
|     if (!targetImport.n) { | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| if (import.meta.rerender === 'client') console.log(true); | ||||
|  | @ -47,4 +47,9 @@ describe('transform core js path', () => { | |||
|     expect(await transformImport(orignalCode, coreJsPath)) | ||||
|       .toBe('var _object_spread = require(\'@swc/helpers/cjs/_object_spread.cjs\')._;module.exports = {};'); | ||||
|   }); | ||||
|   it('with import.meta', async () => { | ||||
|     const orignalCode = fs.readFileSync(path.join(__dirname, './fixtures/transformImport/importMeta.js'), 'utf-8'); | ||||
|     expect(await transformImport(orignalCode, coreJsPath)) | ||||
|       .toBe('if (import.meta.rerender === \'client\') console.log(true);'); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue