From 1d4169204cdc870a084a3371500d7b3ab8546bc2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 21 Aug 2024 13:12:56 -0400 Subject: fix: warn about import assertions when using typescript (#25135) 1. On emit, checks for the prescence of import assertions. 1. Warns and doesn't store the parsed source in the emit cache in this case. --- tests/specs/run/ts_import_assertions/__test__.jsonc | 18 ++++++++++++++++++ tests/specs/run/ts_import_assertions/assertion.out | 14 ++++++++++++++ tests/specs/run/ts_import_assertions/assertion.ts | 5 +++++ tests/specs/run/ts_import_assertions/data.json | 3 +++ tests/specs/run/ts_import_assertions/with.out | 2 ++ tests/specs/run/ts_import_assertions/with.ts | 3 +++ tests/testdata/import_attributes/json_with_shebang.ts | 3 +-- tests/testdata/import_attributes/static_export.out | 6 ++++++ tests/testdata/import_attributes/static_import.out | 6 ++++++ tests/testdata/run/config_json_import.ts | 2 +- 10 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/specs/run/ts_import_assertions/__test__.jsonc create mode 100644 tests/specs/run/ts_import_assertions/assertion.out create mode 100644 tests/specs/run/ts_import_assertions/assertion.ts create mode 100644 tests/specs/run/ts_import_assertions/data.json create mode 100644 tests/specs/run/ts_import_assertions/with.out create mode 100644 tests/specs/run/ts_import_assertions/with.ts (limited to 'tests') diff --git a/tests/specs/run/ts_import_assertions/__test__.jsonc b/tests/specs/run/ts_import_assertions/__test__.jsonc new file mode 100644 index 000000000..dc5576bd1 --- /dev/null +++ b/tests/specs/run/ts_import_assertions/__test__.jsonc @@ -0,0 +1,18 @@ +{ + "tests": { + "assertion": { + "steps": [{ + "args": "run assertion.ts", + "output": "assertion.out" + }, { + // should output the same because the emit won't be cached + "args": "run assertion.ts", + "output": "assertion.out" + }] + }, + "with": { + "args": "run with.ts", + "output": "with.out" + } + } +} diff --git a/tests/specs/run/ts_import_assertions/assertion.out b/tests/specs/run/ts_import_assertions/assertion.out new file mode 100644 index 000000000..3cc900d64 --- /dev/null +++ b/tests/specs/run/ts_import_assertions/assertion.out @@ -0,0 +1,14 @@ +⚠️ Import assertions are deprecated. Use `with` keyword, instead of 'assert' keyword. + +import test from "./data.json" assert { type: "json" }; + + at file:///[WILDLINE]/assertion.ts:1:1 + +{ prop: "data" } +⚠️ Import assertions are deprecated. Use `with` keyword, instead of 'assert' keyword. + +console.log((await import("./data.json", { + + at file:///[WILDLINE]/assertion.ts:5:13 + +{ prop: "data" } diff --git a/tests/specs/run/ts_import_assertions/assertion.ts b/tests/specs/run/ts_import_assertions/assertion.ts new file mode 100644 index 000000000..cb653ffc7 --- /dev/null +++ b/tests/specs/run/ts_import_assertions/assertion.ts @@ -0,0 +1,5 @@ +import test from "./data.json" assert { type: "json" }; +console.log(test); +console.log( + (await import("./data.json", { assert: { type: "json" } })).default, +); diff --git a/tests/specs/run/ts_import_assertions/data.json b/tests/specs/run/ts_import_assertions/data.json new file mode 100644 index 000000000..e5b07266c --- /dev/null +++ b/tests/specs/run/ts_import_assertions/data.json @@ -0,0 +1,3 @@ +{ + "prop": "data" +} diff --git a/tests/specs/run/ts_import_assertions/with.out b/tests/specs/run/ts_import_assertions/with.out new file mode 100644 index 000000000..6141f8c07 --- /dev/null +++ b/tests/specs/run/ts_import_assertions/with.out @@ -0,0 +1,2 @@ +{ prop: "data" } +{ prop: "data" } diff --git a/tests/specs/run/ts_import_assertions/with.ts b/tests/specs/run/ts_import_assertions/with.ts new file mode 100644 index 000000000..58b7fb03d --- /dev/null +++ b/tests/specs/run/ts_import_assertions/with.ts @@ -0,0 +1,3 @@ +import test from "./data.json" with { type: "json" }; +console.log(test); +console.log((await import("./data.json", { with: { type: "json" } })).default); diff --git a/tests/testdata/import_attributes/json_with_shebang.ts b/tests/testdata/import_attributes/json_with_shebang.ts index 0a785210f..9524026bc 100644 --- a/tests/testdata/import_attributes/json_with_shebang.ts +++ b/tests/testdata/import_attributes/json_with_shebang.ts @@ -1,4 +1,3 @@ -// deno-lint-ignore no-import-assertions -import json from "./json_with_shebang.json" assert { type: "json" }; +import json from "./json_with_shebang.json" with { type: "json" }; console.log(json); diff --git a/tests/testdata/import_attributes/static_export.out b/tests/testdata/import_attributes/static_export.out index 41af79d7c..d7e19c80f 100644 --- a/tests/testdata/import_attributes/static_export.out +++ b/tests/testdata/import_attributes/static_export.out @@ -1 +1,7 @@ +⚠️ Import assertions are deprecated. Use `with` keyword, instead of 'assert' keyword. + +export { default } from "./data.json" assert { type: "json" }; + + at file:///[WILDLINE] + { a: "b", c: { d: 10 } } diff --git a/tests/testdata/import_attributes/static_import.out b/tests/testdata/import_attributes/static_import.out index e57dffa99..85c75d3eb 100644 --- a/tests/testdata/import_attributes/static_import.out +++ b/tests/testdata/import_attributes/static_import.out @@ -1,2 +1,8 @@ +⚠️ Import assertions are deprecated. Use `with` keyword, instead of 'assert' keyword. + +import data2 from "./data.json" assert { type: "json" }; + + at file:///[WILDLINE] + { a: "b", c: { d: 10 } } { a: "b", c: { d: 10 } } diff --git a/tests/testdata/run/config_json_import.ts b/tests/testdata/run/config_json_import.ts index 9cf1cceaa..7141f1495 100644 --- a/tests/testdata/run/config_json_import.ts +++ b/tests/testdata/run/config_json_import.ts @@ -1,2 +1,2 @@ -import config from "../jsx/deno-jsx.json" assert { type: "json" }; +import config from "../jsx/deno-jsx.json" with { type: "json" }; console.log(config); -- cgit v1.2.3