Skip to content

add missing keywords to JS and TS#1741

Merged
Anteru merged 1 commit intopygments:masterfrom
Mesteery:patch-1
May 2, 2021
Merged

add missing keywords to JS and TS#1741
Anteru merged 1 commit intopygments:masterfrom
Mesteery:patch-1

Conversation

@Mesteery
Copy link
Copy Markdown
Contributor

@Mesteery Mesteery commented Mar 8, 2021

from keyword was missing (import something from 'something')

@Anteru Anteru self-assigned this Mar 8, 2021
@Anteru Anteru added this to the 2.9 milestone Mar 8, 2021
@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Mar 8, 2021
@Anteru
Copy link
Copy Markdown
Collaborator

Anteru commented Mar 8, 2021

from is not a keyword though, is it? I was just trying to look up ES5/6 reserved words and from doesn't show up there (source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar). Is it only contextual?

And should as be also supported?

@Mesteery
Copy link
Copy Markdown
Contributor Author

Mesteery commented Mar 8, 2021

The from (and as) is used with ESM imports/exports.

@Anteru
Copy link
Copy Markdown
Collaborator

Anteru commented Mar 8, 2021

I know, my point is though that from/as are not official keywords, or are they? I'm trying to understand if treating them the same as "import" is correct, given that is reserved. as seems to be missing in any case, could you please add that while you're at this?

@Mesteery
Copy link
Copy Markdown
Contributor Author

Mesteery commented Mar 8, 2021

Those that are always allowed as identifiers, but also appear as keywords within certain syntactic productions, at places where Identifier is not allowed: as, async, from, get, of, set, and target.

https://tc39.es/ecma262/2020/#sec-keywords-and-reserved-words

Also removed invalid "AS" from TypeScript lexer.
@Mesteery Mesteery changed the title add "from" to js and ts keywords add "from" and "as" to js and ts keywords Mar 8, 2021
@Mesteery
Copy link
Copy Markdown
Contributor Author

Mesteery commented Mar 8, 2021

For a more general PR, we could add :

  • more errors (Error, EvalError, InternalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError) as Name.Exception ?
  • the global object (Name.Builtin, Node.js)
  • more Name.Builtin (such as typed arrays, Intl, DataView, Set, Map, WeakSet, WeakMap, Reflect, JSON, ArrayBuffer, Atomics) ?
  • highlight \\..., \n, \r, \v, \t, \b, \f, \uXXXX (U+0000 - U+FFFF), \xXX (0x00 - 0xFF) as String.Escape (same as Python lexer)
  • **, **=, >>>=, ??, &&=, ||=, ??= as Operator
  • typeof, instanceof, in, void, delete, new as Operator.Word
  • use the same base for JavaScript and TypeScript lexers (same operators, ...)

@Mesteery Mesteery changed the title add "from" and "as" to js and ts keywords update javascript lexers Mar 8, 2021
@Mesteery Mesteery changed the title update javascript lexers update javascript lexer Mar 8, 2021
@Mesteery Mesteery marked this pull request as draft March 8, 2021 19:15
@Anteru
Copy link
Copy Markdown
Collaborator

Anteru commented Mar 14, 2021

Yes, that sounds good, but I'd rather do it in a separate PR. This here is nice and self-contained. Can you please un-draft it so I can merge it, then file another PR for the other changes?

@Mesteery Mesteery marked this pull request as ready for review March 14, 2021 10:02
@Mesteery Mesteery changed the title update javascript lexer add missing keywords to JS and TS Apr 20, 2021
@Mesteery Mesteery mentioned this pull request Apr 20, 2021
9 tasks
@Anteru Anteru merged commit 0da640a into pygments:master May 2, 2021
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label May 2, 2021
@Mesteery Mesteery deleted the patch-1 branch May 2, 2021 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants