@@ -67,6 +67,7 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav
67
67
->method ('getAssetFromSourcePath ' )
68
68
->willReturnCallback (function ($ path ) {
69
69
return match ($ path ) {
70
+ '/project/assets/foo.js ' => new MappedAsset ('foo.js ' , '/can/be/anything.js ' , publicPathWithoutDigest: '/assets/foo.js ' ),
70
71
'/project/assets/other.js ' => new MappedAsset ('other.js ' , '/can/be/anything.js ' , publicPathWithoutDigest: '/assets/other.js ' ),
71
72
'/project/assets/subdir/foo.js ' => new MappedAsset ('subdir/foo.js ' , '/can/be/anything.js ' , publicPathWithoutDigest: '/assets/subdir/foo.js ' ),
72
73
'/project/assets/styles.css ' => new MappedAsset ('styles.css ' , '/can/be/anything.js ' , publicPathWithoutDigest: '/assets/styles.css ' ),
@@ -269,6 +270,63 @@ public static function provideCompileTests(): iterable
269
270
'expectedJavaScriptImports ' => ['/assets/other.js ' => ['lazy ' => true , 'asset ' => 'other.js ' , 'add ' => true ]],
270
271
];
271
272
273
+ yield 'import_in_double_quoted_string_is_ignored ' => [
274
+ 'input ' => <<<EOF
275
+ const fun;
276
+ console.log("import('./foo.js')");
277
+ EOF
278
+ ,
279
+ 'expectedJavaScriptImports ' => [],
280
+ ];
281
+
282
+ yield 'import_in_double_quoted_string_with_escaped_quote_is_ignored ' => [
283
+ 'input ' => <<<EOF
284
+ const fun;
285
+ console.log(" foo \" import('./foo.js')");
286
+ EOF
287
+ ,
288
+ 'expectedJavaScriptImports ' => [],
289
+ ];
290
+
291
+ yield 'import_in_single_quoted_string_is_ignored ' => [
292
+ 'input ' => <<<EOF
293
+ const fun;
294
+ console.log('import("./foo.js")');
295
+ EOF
296
+ ,
297
+ 'expectedJavaScriptImports ' => [],
298
+ ];
299
+
300
+ yield 'import_after_a_string_is_parsed ' => [
301
+ 'input ' => <<<EOF
302
+ const fun;
303
+ console.log("import('./other.js')"); import("./foo.js");
304
+ EOF
305
+ ,
306
+ 'expectedJavaScriptImports ' => ['/assets/foo.js ' => ['lazy ' => true , 'asset ' => 'foo.js ' , 'add ' => true ]],
307
+ ];
308
+
309
+ yield 'import_before_a_string_is_parsed ' => [
310
+ 'input ' => <<<EOF
311
+ const fun;
312
+ import("./other.js"); console.log("import('./foo.js')");
313
+ EOF
314
+ ,
315
+ 'expectedJavaScriptImports ' => ['/assets/other.js ' => ['lazy ' => true , 'asset ' => 'other.js ' , 'add ' => true ]],
316
+ ];
317
+
318
+ yield 'import_before_and_after_a_string_is_parsed ' => [
319
+ 'input ' => <<<EOF
320
+ const fun;
321
+ import("./other.js"); console.log("import('./foo.js')"); import("./subdir/foo.js");
322
+ EOF
323
+ ,
324
+ 'expectedJavaScriptImports ' => [
325
+ '/assets/other.js ' => ['lazy ' => true , 'asset ' => 'other.js ' , 'add ' => true ],
326
+ '/assets/subdir/foo.js ' => ['lazy ' => true , 'asset ' => 'subdir/foo.js ' , 'add ' => true ],
327
+ ],
328
+ ];
329
+
272
330
yield 'bare_import_not_in_importmap ' => [
273
331
'input ' => 'import "some_module"; ' ,
274
332
'expectedJavaScriptImports ' => [],
0 commit comments