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

JS: Handle meta-properties new.target and import.meta and improve code completion with newlines and comments #7211

Merged
merged 4 commits into from
Apr 10, 2024

Conversation

matthiasblaesing
Copy link
Contributor

JS currently provides two meta-properties:

  • new.target
  • import.meta

new.target was already partially supported and lexed as a single identifier. This makes it hard to support embedded comments or new lines. MDN describes both as properties as:

The import.meta syntax consists of the keyword import, a dot, and the identifier meta. Because import is a reserved word not an identifier, this is not a property accessor but a special expression syntax.

The lexer lexes import.meta and new.target as three tokens:

  • Keyword new or import
  • Operator .
  • Identifier target or meta

The parser will handle it slightly different and create an AccessNode with the property name target or import on an IdentNode new or import.

In addition the handling of new lines and comments in expression chains (obj.prop1.prop2) was improved.

Closes: #5919

…get (already supported)

Parsing was modified to report 'new.target' as an AccessNode on an
IdentNode 'new' with property 'target'. 'import.meta' is modelled
identically.
… and import.meta

The JS parser reports new.target as an AccessNode for the property
"target" on the IdentNode "new". The parser has no KeyWord Node, else
that would be the best choice.

The lexer lexes new.target as three tokens:

- Keyword "new"
- Operator "."
- Identifier "target"
@matthiasblaesing matthiasblaesing added JavaScript [ci] enable web job and extra JavaScript tests (webcommon/javascript2.editor) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Mar 30, 2024
@matthiasblaesing matthiasblaesing added this to the NB22 milestone Mar 30, 2024
Both new.target and import.meta are declared as special properties with
special semantic as they are properties on keywords. The approach taken
here is to declare a helper object "metaproperties", declare the "new"
and "import" properties and their children there. After parsing the
properties are relocated from metaproperties into the global object,
where they will be picked up by the JsCompletion.
@matthiasblaesing
Copy link
Contributor Author

This was successfully tested - so lets get it in.

@matthiasblaesing matthiasblaesing merged commit 1768511 into apache:master Apr 10, 2024
34 checks passed
@matthiasblaesing matthiasblaesing deleted the js-import-meta branch April 19, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) JavaScript [ci] enable web job and extra JavaScript tests (webcommon/javascript2.editor)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Javascript syntax parser: import.meta.url not recognised
1 participant