|
| 1 | +'use strict'; |
| 2 | +constcommon=require('../common'); |
| 3 | +constfixtures=require('../common/fixtures'); |
| 4 | +constassert=require('assert'); |
| 5 | +const{ pathToFileURL }=require('url'); |
| 6 | + |
| 7 | +assert.rejects( |
| 8 | +import('data:text/javascript,require;'), |
| 9 | +/requireisnotdefinedinESmodulescope,youcanuseimportinstead$/ |
| 10 | +).then(common.mustCall()); |
| 11 | +assert.rejects( |
| 12 | +import('data:text/javascript,exports={};'), |
| 13 | +/exportsisnotdefinedinESmodulescope$/ |
| 14 | +).then(common.mustCall()); |
| 15 | + |
| 16 | +assert.rejects( |
| 17 | +import('data:text/javascript,require_custom;'), |
| 18 | +/^(?!inESmodulescope)(?!useimportinstead).*$/ |
| 19 | +).then(common.mustCall()); |
| 20 | + |
| 21 | +constpkgUrl=pathToFileURL(fixtures.path('/es-modules/package-type-module/')); |
| 22 | +assert.rejects( |
| 23 | +import(newURL('./cjs.js',pkgUrl)), |
| 24 | +/usethe'\.cjs'fileextension/ |
| 25 | +).then(common.mustCall()); |
| 26 | +assert.rejects( |
| 27 | +import(newURL('./cjs.js#target',pkgUrl)), |
| 28 | +/usethe'\.cjs'fileextension/ |
| 29 | +).then(common.mustCall()); |
| 30 | +assert.rejects( |
| 31 | +import(newURL('./cjs.js?foo=bar',pkgUrl)), |
| 32 | +/usethe'\.cjs'fileextension/ |
| 33 | +).then(common.mustCall()); |
| 34 | +assert.rejects( |
| 35 | +import(newURL('./cjs.js?foo=bar#target',pkgUrl)), |
| 36 | +/usethe'\.cjs'fileextension/ |
| 37 | +).then(common.mustCall()); |
| 38 | + |
| 39 | +assert.rejects( |
| 40 | +import('data:text/javascript,require;//.js'), |
| 41 | +/^(?!usethe'\.cjs'fileextension).*$/ |
| 42 | +).then(common.mustCall()); |
0 commit comments