-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for import assertions and JSON modules #12866
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a5b25bb
add deno_core::ModuleType enum
bartlomieju 0c97bcf
remove atomic in core/modules.rs
bartlomieju a4ec823
Merge branch 'main' into import_assertions
bartlomieju 2cb253c
Merge branch 'main' into import_assertions
bartlomieju 53016b0
Merge branch 'main' into import_assertions
bartlomieju cf72c70
Merge branch 'main' into import_assertions
bartlomieju d8eeb8f
Merge branch 'main' into import_assertions
bartlomieju 4098ebd
use ModuleType
bartlomieju a1c5f54
check passed assertion value
bartlomieju 1e6f134
validate import assertions
bartlomieju 795dcce
example(core): add example for FS module loading
bartlomieju cf7c69d
fix cargo lock, add ModuleType::Json
bartlomieju ce0117f
fix
bartlomieju f06d9ba
Merge branch 'core_example_loading' into import_assertions
bartlomieju 4b0cf46
update WPT expectations
bartlomieju 694ae08
Merge branch 'main' into import_assertions
bartlomieju 73f20db
JSON module evaluation
bartlomieju f881a94
fmt
bartlomieju 54fa3e8
Merge branch 'main' into import_assertions
bartlomieju 2cabd3c
parsing of assertions
bartlomieju e4ad657
add ModuleRequest struct
bartlomieju acc2ac0
import functions
bartlomieju b1ae3f2
wire up in the CLI
bartlomieju 4535edb
fix validation of assertions
bartlomieju 6a549ca
lint
bartlomieju 1cb9bdf
add tests, set resolveJsonModule in tsc
bartlomieju 37a464c
review comments
bartlomieju da0ba53
update TS config for LSP
bartlomieju 6c8be58
add wildcard to test output
bartlomieju 519de28
work around bug in deno_ast
kitsonk 853982d
revert change to display
bartlomieju 48590d8
ignore emit for json modules
kitsonk 9627341
update output assertions
bartlomieju fb8295f
add test for type checking JSON module
bartlomieju 98fdbf7
fmt
bartlomieju c533c65
use SyntaxError for invalid JSON
bartlomieju 3fe6133
update WPT
bartlomieju 50e9299
update WPT2
bartlomieju 0428fa6
lint
bartlomieju 265a408
pass another WPT test
bartlomieju fab5d86
review comments
bartlomieju a5dbc9c
fix tests
bartlomieju f0662ff
Merge branch 'main' into import_assertions
bartlomieju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"a": "b", | ||
"c": { | ||
"d": 10 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[WILDCARD] | ||
error: Uncaught (in promise) TypeError: Expected a "JavaScript" module but loaded a "JSON" module. | ||
const data = await import("./data.json"); | ||
^ | ||
at async [WILDCARD]dynamic_error.ts:1:14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const data = await import("./data.json"); | ||
|
||
console.log(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[WILDCARD] | ||
Module { default: { a: "b", c: { d: 10 } } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const data = await import("./data.json", { assert: { type: "json" } }); | ||
|
||
console.log(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[WILDCARD] | ||
error: An unsupported media type was attempted to be imported as a module. | ||
Specifier: [WILDCARD]data.json | ||
MediaType: Json | ||
at [WILDCARD]static_error.ts:1:18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import data from "./data.json"; | ||
|
||
console.log(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[WILDCARD] | ||
{ a: "b", c: { d: 10 } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import data from "./static_reexport.ts"; | ||
|
||
console.log(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[WILDCARD] | ||
{ a: "b", c: { d: 10 } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import data from "./data.json" assert { type: "json" }; | ||
|
||
console.log(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./data.json" assert { type: "json" }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[WILDCARD] | ||
error: TS2339 [ERROR]: Property 'foo' does not exist on type '{ a: string; c: { d: number; }; }'. | ||
console.log(data.foo); | ||
~~~ | ||
at [WILDCARD]type_check.ts:3:18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import data from "./data.json" assert { type: "json" }; | ||
|
||
console.log(data.foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Seems like something that could be extracted out into a function to help reduce the detail here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used in a single place, and the whole function seems like a code smell, I'd rather address this in separate PR that would cleanup modules implementation