• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const fixtures = require('../common/fixtures');
4const assert = require('assert');
5const { pathToFileURL } = require('url');
6
7assert.rejects(
8  import('data:text/javascript,require;'),
9  /require is not defined in ES module scope, you can use import instead$/
10).then(common.mustCall());
11assert.rejects(
12  import('data:text/javascript,exports={};'),
13  /exports is not defined in ES module scope$/
14).then(common.mustCall());
15
16assert.rejects(
17  import('data:text/javascript,require_custom;'),
18  /^(?!in ES module scope)(?!use import instead).*$/
19).then(common.mustCall());
20
21const pkgUrl = pathToFileURL(fixtures.path('/es-modules/package-type-module/'));
22assert.rejects(
23  import(new URL('./cjs.js', pkgUrl)),
24  /use the '\.cjs' file extension/
25).then(common.mustCall());
26assert.rejects(
27  import(new URL('./cjs.js#target', pkgUrl)),
28  /use the '\.cjs' file extension/
29).then(common.mustCall());
30assert.rejects(
31  import(new URL('./cjs.js?foo=bar', pkgUrl)),
32  /use the '\.cjs' file extension/
33).then(common.mustCall());
34assert.rejects(
35  import(new URL('./cjs.js?foo=bar#target', pkgUrl)),
36  /use the '\.cjs' file extension/
37).then(common.mustCall());
38
39assert.rejects(
40  import('data:text/javascript,require;//.js'),
41  /^(?!use the '\.cjs' file extension).*$/
42).then(common.mustCall());
43