Skip to content

import(data:text/javascript,) throw SyntaxError #42504

@lovetingyuan

Description

@lovetingyuan

Version

v16.14.2

Platform

Darwin tingyuandeMacBook-Pro.local 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

const c = `
var config0 = {
  text: '{{ a => a === "aa" ? "bb" : "cc" }}'
};
var _configs = { "aa": config0 };
var configFiles = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  "default": _configs
}, Symbol.toStringTag, { value: "Module" }));
export { configFiles as default };
`;
import(`data:text/javascript,${c}`).then((res) => {
  console.log(res);
});

Just run the code with latest node, error is here:

data:text/javascript,var config0 = {  text: '{{ a => a === "aa" ?%20%22bb%22%20:%20%22cc%22%20}}'};var%20_configs%20=%20{%20%22aa%22:%20config0%20};var%20configFiles%20=%20/*%20@__PURE__%20*/%20Object.freeze(/*%20@__PURE__%20*/%20Object.defineProperty({%20%20__proto__:%20null,%20%20%22default%22:%20_configs},%20Symbol.toStringTag,%20{%20value:%20%22Module%22%20}));export%20{%20configFiles%20as%20default%20};:1
var config0 = {  text: '{{ a => a === "aa" 
                       ^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:115:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:289:14)
    at async link (node:internal/modules/esm/module_job:70:21)

but, in chrome, the code runs well, no error.
image

How often does it reproduce? Is there a required condition?

100% reproduce.

What is the expected behavior?

no error should be thrown, It seems related to ?(ternary operator).

What do you see instead?

node can not run the code, but chrome can run the same code.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions