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

Normative: Add Import Attributes #3057

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented May 8, 2023

This proposal (https://tc39.es/proposal-import-attributes/, https://github.com/tc39/proposal-import-attributes) reached stage 3 during the March 2023 meeting, conditional on stage 3 reviews. I'm opening this PR before "real" stage 3 to help editors reviewing the full spec changes.

The proposal has already been integrated in HTML: https://html.spec.whatwg.org/#hostloadimportedmodule

PREVIEW: https://ci.tc39.es/preview/tc39/ecma262/pull/3057
DIFF: https://arai-a.github.io/ecma262-compare/?pr=3057 (note: the diff doesn't mark deprecated sections)

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@nicolo-ribaudo nicolo-ribaudo added normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 and removed pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. labels May 8, 2023
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented May 22, 2023

@tc39/ecma262-editors Currently the only remaining condition for this proposal to be actually Stage 3 is the editorial review. It'd be great if you have time to do it :)

@bakkot bakkot added the editor call to be discussed in the next editor call label May 24, 2023
Copy link
Contributor

@bakkot bakkot left a comment

Choose a reason for hiding this comment

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

LGTM other than comments.

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@nicolo-ribaudo
Copy link
Member Author

I pushed two more normative commits, that are oversights from the assert->with migration:

  1. Added assert as an alternative to with also in export ... from statements
  2. Removed the [no LineTerminator here] restriction before with
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
Copy link
Collaborator

@jmdyck jmdyck left a comment

Choose a reason for hiding this comment

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

There are various SDOs defined on the current forms of ImportCall, ImportDeclaration, and/or ExportDeclaration that are not defined on the new forms:

  • BoundNames
  • Evaluation
  • ExportEntries
  • ExportedBindings
  • ExportedNames
  • HasCallInTailPosition
  • ImportEntries
  • LexicallyScopedDeclarations
  • ModuleRequests
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated

<p>The following augments the |ImportDeclaration| and |ExportDeclaration| productions in <emu-xref href="#sec-imports"></emu-xref> and <emu-xref href="#sec-exports"></emu-xref>:</p>
<!-- emu-grammar[type=definition] have different margin than other emu-grammar, but we want this to be aligned with the one below. -->
<emu-grammar style="display:block; margin-left: 5ex">
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think this should be marked type="definition" (and ecmarkup should be modified to treat it appropriately).

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Actually, at this point, even if ecmarkup isn't modified, the effect should be pretty minor, since AttributesKeyword is the only affected nonterminal now.)

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 will try to modify ecmarkup. It already supports duplicated definitions, but only in annexes.

@nicolo-ribaudo
Copy link
Member Author

I pushed two new commits:

  1. Validate attrs when lodaing deps and not when parsing fixes Invalid attributes keys in static imports should be a resolution/loading error and not a parsing error proposal-import-attributes#144. From an ECMA-262 point of view this is purely editorial, because:
    • it's not currently observable whether an error is thrown when parsing or when calling LoadImportedModules()
    • code that resulted in a syntax error still results in a syntax error, and vice versa. there might be a difference in the location of the reported syntax error (see the example in the linked issue), but that's already completely implementation-defined.
  2. Merge AssertClause into WithClause, and fix missing SDOs while fixing Normative: Add Import Attributes #3057 (review) I realized that I had to duplicate every SDO using WithClause into exactly the same definition but using AssertClause. There are many of them, and copy-pasting risks introducing problems when we update one and forget to update the other one. I ended up merging the two productions as originally suggested by @bakkot in Normative: Add Import Attributes #3057 (comment), but with a production parameter to only allow assert in the [no LineTerminator here] case.
spec.html Outdated Show resolved Hide resolved
@jmdyck
Copy link
Collaborator

jmdyck commented Jun 26, 2023

Why not just tweak @bakkot's suggestion into:

AttributesKeyword :
  `with`
  [no LineTerminator here] `assert`

That would eliminate the [DeprecatedAssert] parameter and the deprecated definitions of ImportDeclaration and ExportDeclaration.

@nicolo-ribaudo
Copy link
Member Author

[no LineTerminator here] is never used at the beginning/end of a production currently, but if the editors like that I think it's a very good idea.

@nicolo-ribaudo
Copy link
Member Author

I pushed @jmdyck's suggestion, to show how much it would simplify the spec.

@jmdyck
Copy link
Collaborator

jmdyck commented Jun 26, 2023

[no LineTerminator here] is never used at the beginning/end of a production currently,

A [no LineTerminator here] constraint is similar in flavor to a [lookahead ...] constraint, and we have lots of occurrences of those at the start + end of productions (4 at the start, 24 at the end).

And there's nothing in the definition of [no LineTerminator here] that would preclude its use at the start/end of a production.

So I don't think we should have any qualms about using it in this way.

@jmdyck
Copy link
Collaborator

jmdyck commented Jun 26, 2023

I think the ModuleRequests SDO needs rule(s) to handle:

`import` ModuleSpecifier WithClause? `;`
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated
1. Assert: Exactly one element of _referrer_.[[LoadedModules]] is a Record whose [[Specifier]] is _specifier_, since LoadRequestedModules has completed successfully on _referrer_ prior to invoking this abstract operation.
1. Let _record_ be the Record in _referrer_.[[LoadedModules]] whose [[Specifier]] is _specifier_.
1. Assert: Exactly one element of _referrer_.[[LoadedModules]] is a LoadedModuleRequest Record _record_ such that ModuleRequestsEqual(_record_, _request_) is *true*, since LoadRequestedModules has completed successfully on _referrer_ prior to invoking this abstract operation.
1. Let _record_ be the LoadedModuleRequest Record in _referrer_.[[LoadedModules]] such that ModuleRequestsEqual(_record_, _request_) is *true*.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The form of this Let step is unusual. Normally, in Let _foo_ be <something>, the alias _foo_ doesn't appear in <something>.

For the 2 steps, maybe something more like:

1. Let _x_ be a List consisting of
     each LoadedModuleRequest Record _record_
     of _referrer_.[[LoadedModules]] such that etc.
3. Assert: _x_ has exactly one element.
4. Let _record_ be the sole element of _x_.

(That also eliminates the duplication between the two steps.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh ecmarkup's linting doesn't like this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, given

... a List consisting of each LoadedModuleRequest Record _r_
    of _referrer_.[[LoadedModules]] such that <condition>

ecmarkup is saying that it can't find a preceding declaration for _r_. That is, it's treating this occurrence of _r_ as a 'use', whereas it's syntactically a declaration.

@bakkot: could ecmarkup be modified to treat this as a declaration?

spec.html Outdated

<p>The following augments the |ImportDeclaration| and |ExportDeclaration| productions in <emu-xref href="#sec-imports"></emu-xref> and <emu-xref href="#sec-exports"></emu-xref>:</p>
<!-- emu-grammar[type=definition] have different margin than other emu-grammar, but we want this to be aligned with the one below. -->
<emu-grammar style="display:block; margin-left: 5ex">
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Actually, at this point, even if ecmarkup isn't modified, the effect should be pretty minor, since AttributesKeyword is the only affected nonterminal now.)

spec.html Outdated Show resolved Hide resolved
@nicolo-ribaudo
Copy link
Member Author

PR updated to remove support for float and bigint literal keys, as per consensus in the TC39 2023-09 meeting.

spec.html Outdated Show resolved Hide resolved
* Add Import Attributes proposal
* `npm run format`
* Updates from review
* Changes from review
* Do not re-define ImportDeclaration
* Add `assert` deprecated syntax to `export ... from`
* Remove `[no LineTerminator here]` before `with`
* Use optional symbols to reduce grammar
* Update ImportEntries and ExportEntry to use ModuleRequest Records
* Review from Michael
* Replace AttributeKey with LiteralPropertyName
* Separate ModuleRequest and LoadedModuleRequest fields
* Validate attrs when lodaing deps and not when parsing
* Merge `AssertClause` into `WithClause`, and fix missing SDOs
* Fix type annotation
* Simplify AttributesKeyword
* Reviews
* Review
* Remove support for float and bigint literal keys
* Update wording
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4.
6 participants