Skip to content
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

Add import assertions #17366

Merged
merged 12 commits into from Nov 22, 2022
Merged

Add import assertions #17366

merged 12 commits into from Nov 22, 2022

Conversation

Josh-Cena
Copy link
Member

@Josh-Cena Josh-Cena commented Aug 15, 2022

Summary

Fixes #14052, fixes #14053, part of mdn/content#19220

First time doing actual compat data changes... I don't really know how this ought to be done. I don't know if this addresses #14053 either.

Test results and supporting details

See https://v8.dev/features/import-assertions

Node versions are hand-tested.

Related issues

@github-actions github-actions bot added the data:js 📟 Compat data for JS/ECMAScript features. https://developer.mozilla.org/docs/Web/JavaScript label Aug 15, 2022
Comment on lines 69 to 71
"options": {
"__compat": {
"description": "The second options parameter",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called it "options" instead of "assertions", because unlike the import statement, the options here permit any unknown attributes from the start, so other keys won't throw parser errors either. In this case, should "assertions" be separately listed as a subfeature to increase discoverability?

Copy link
Collaborator

@queengooborg queengooborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a couple of quick updates, and then this will be LGTM!

javascript/operators/import.json Outdated Show resolved Hide resolved
javascript/statements.json Outdated Show resolved Hide resolved
javascript/operators/import.json Outdated Show resolved Hide resolved
javascript/operators/import.json Outdated Show resolved Hide resolved
javascript/operators/import.json Outdated Show resolved Hide resolved
javascript/statements.json Outdated Show resolved Hide resolved
javascript/statements.json Outdated Show resolved Hide resolved
javascript/statements.json Outdated Show resolved Hide resolved
Co-authored-by: Queen Vinyl Da.i'gyu-Kazotetsu <vinyldarkscratch@gmail.com>
Copy link
Collaborator

@queengooborg queengooborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fixes!

@queengooborg queengooborg enabled auto-merge (squash) August 15, 2022 10:25
@Josh-Cena
Copy link
Member Author

"16.14.0" is NOT a valid version number for nodejs

Okay that looks hilarious...

Also, I'm pretty confident it should be called experimental, since we only have V8 support.

@queengooborg
Copy link
Collaborator

Experimental set to true sounds good to me!

I've opened up #17367 to add v16.14.0 to the browser data, and will merge that promptly so this PR passes!

Copy link
Collaborator

@queengooborg queengooborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we should actually set the second of the three NodeJS statements to partial_implementation, since there are extra details to note regarding compatibility.

By the way, should we create a subfeature for the json assertion type? It might be a little easier to represent the fact that NodeJS added support for the type in 16.15.0 and 17.5.0 (AKA 17.0.0 through 17.4.0 did not have support).

javascript/statements.json Outdated Show resolved Hide resolved
javascript/operators/import.json Show resolved Hide resolved
@Josh-Cena
Copy link
Member Author

It's complicated for JSON modules. IIRC it's unflagged in 17.5, but backported to 16.15. I don't think we've reached resolution on what to do in that case—do we? I also don't plan to address #14053 — just focusing on the syntax in this PR. JSON modules would also involve web API I think. (Again it's complicated.)

auto-merge was automatically disabled August 15, 2022 11:04

Head branch was pushed to by a user without write access

Josh-Cena and others added 2 commits August 15, 2022 19:04
Co-authored-by: Queen Vinyl Da.i'gyu-Kazotetsu <vinyldarkscratch@gmail.com>
Co-authored-by: Queen Vinyl Da.i'gyu-Kazotetsu <vinyldarkscratch@gmail.com>
@queengooborg
Copy link
Collaborator

In a case like that, I'd say that we should do the following:

[
  {
    "version_added": "17.5.0"
  },
  {
    "version_added": "16.15.0",
    "version_removed": "17.0.0"
  },
  {
    "version_added": "17.0.0",
    "version_removed": "17.5.0",
    "flags": [
      {
        "type": "runtime_flag",
        "name": "--experimental-json-modules"
      }
    ]
  },
  {
    "version_added": "16.0.0",
    "version_removed": "16.15.0",
    "flags": [
      {
        "type": "runtime_flag",
        "name": "--experimental-json-modules"
      }
    ]
  }
]

It's kind of messy, especially with the flag data, but it's the best we can do with Node's LTS release cycle. WDYT?

@Josh-Cena
Copy link
Member Author

Josh-Cena commented Aug 15, 2022

This problem is kind of non-unique—also present in #15123.

Also, do you want to me to do the --experimental-json-modules flag in this PR as well? Frankly I didn't check that. In fact JSON modules and import assertions are two separate things: the latter is merely syntax. I only included a "partial implementation" note about JSON modules in Node for convenience.

@queengooborg
Copy link
Collaborator

Yeah, it's an ugly solution, but I feel it is a necessary one due to how NodeJS' release cycle works. On the plus side, doing this allows us to better represent exactly which versions support the feature!

As for the flag, if you're down to incorporate it, that would be great! Otherwise, no big deal; flags quickly become useless to document once they're no longer needed for a feature. ;P

@Josh-Cena
Copy link
Member Author

Josh-Cena commented Oct 31, 2022

Sorry @queengooborg I think I'm a bit lost on this. Could you update the PR in the way you want (or in the form of a suggestion) so we can get to merge this?

@hamishwillee
Copy link
Collaborator

@queengooborg ^^^ Could you please propose fixes as suggestions to unblock this?

@queengooborg
Copy link
Collaborator

I have proposed a solution already, actually -- see #17366 (comment)!

@Josh-Cena
Copy link
Member Author

The flags data for Node is a bit of a mess—there are two flags: --harmony-import-assertions and --experimental-json-modules. The first one enables the parser feature, the second one makes assert { type: "json" } actually "work" (turns on the JSON loader). I don't really know what to do here...

@queengooborg
Copy link
Collaborator

I went ahead and pushed the changes I'm looking to see to reduce the back-and-forth and to help get this merged quicker!

@queengooborg queengooborg merged commit 93e3e68 into mdn:main Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:js 📟 Compat data for JS/ECMAScript features. https://developer.mozilla.org/docs/Web/JavaScript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add data for JSON module imports Add data for import assertions
3 participants