From 9def44979a0c3a03a7ada09f8359ea6b1d795d03 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Sun, 16 Jan 2022 16:48:32 +0100 Subject: fix(cli): Don't strip shebangs from modules (#13220) Deno's module loader currently strips a shebang if a module file starts with one. However, this is no longer necessary, since there is a stage-3 TC39 that adds support for shebangs (or "hashbangs") to the language (https://github.com/tc39/proposal-hashbang), and V8, `tsc` and `swc` all support it. Furthermore, stripping shebangs causes a correctness bug with JSON modules, since a JSON file with a shebang should not parse as a JSON module, yet it does with this stripping. This change fixes this. --- cli/tests/testdata/import_assertions/json_with_shebang.json | 4 ++++ cli/tests/testdata/import_assertions/json_with_shebang.ts | 3 +++ cli/tests/testdata/import_assertions/json_with_shebang.ts.out | 1 + 3 files changed, 8 insertions(+) create mode 100644 cli/tests/testdata/import_assertions/json_with_shebang.json create mode 100644 cli/tests/testdata/import_assertions/json_with_shebang.ts create mode 100644 cli/tests/testdata/import_assertions/json_with_shebang.ts.out (limited to 'cli/tests/testdata/import_assertions') diff --git a/cli/tests/testdata/import_assertions/json_with_shebang.json b/cli/tests/testdata/import_assertions/json_with_shebang.json new file mode 100644 index 000000000..b695e4457 --- /dev/null +++ b/cli/tests/testdata/import_assertions/json_with_shebang.json @@ -0,0 +1,4 @@ +#!/usr/env -S deno run +{ + "test": null +} diff --git a/cli/tests/testdata/import_assertions/json_with_shebang.ts b/cli/tests/testdata/import_assertions/json_with_shebang.ts new file mode 100644 index 000000000..523bf8772 --- /dev/null +++ b/cli/tests/testdata/import_assertions/json_with_shebang.ts @@ -0,0 +1,3 @@ +import json from "./json_with_shebang.json" assert { type: "json" }; + +console.log(json); diff --git a/cli/tests/testdata/import_assertions/json_with_shebang.ts.out b/cli/tests/testdata/import_assertions/json_with_shebang.ts.out new file mode 100644 index 000000000..ae5f3a65f --- /dev/null +++ b/cli/tests/testdata/import_assertions/json_with_shebang.ts.out @@ -0,0 +1 @@ +error: Uncaught SyntaxError: Unexpected token # in JSON at position 0 -- cgit v1.2.3