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

#156. Improve TS declare lexical bindings #259

Merged
merged 4 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
#156. Improve TS declare lexical bindings
  • Loading branch information
STRd6 committed Jan 20, 2023
commit 70080327d8d4ca68c53d2e64dabec5ee3bb77999
21 changes: 14 additions & 7 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -2984,7 +2984,7 @@ ImportedBinding
# https://262.ecma-international.org/#prod-ExportDeclaration
ExportDeclaration
# NOTE: Using ExtendedExportDeclaration to allow If/Switch expressions
Export __ "default" NonIdContinue __ ( HoistableDeclaration / ClassDeclaration / ExtendedExpression )
Export __ Default __ ( HoistableDeclaration / ClassDeclaration / ExtendedExpression )
Export __ ExportFromClause __ FromClause ->
if (!$3.ts) return $0
return { ts: true, children: $0 }
Expand Down Expand Up @@ -3023,7 +3023,7 @@ ExportSpecifier
return { ts: true, children: $0 }

ImplicitExportSpecifier
!"default" ModuleExportName ( __ As __ ModuleExportName )? ( &( __ From ) / ImplicitInlineObjectPropertyDelimiter )
!Default ModuleExportName ( __ As __ ModuleExportName )? ( &( __ From ) / ImplicitInlineObjectPropertyDelimiter )

# https://262.ecma-international.org/#prod-Declaration
Declaration
Expand Down Expand Up @@ -3615,6 +3615,10 @@ ConstructorShorthand
"@" ->
return { $loc, token: "constructor" }

Declare
"declare" NonIdContinue ->
return { $loc, token: $1 }

Default
"default" NonIdContinue ->
return { $loc, token: $1 }
Expand Down Expand Up @@ -4424,18 +4428,21 @@ NestedJSXChildExpression
## Type Stuff

TypeDeclaration
(TypeDeclarationModifier TrailingComment*)* TypeDeclarationRest -> { ts: true, children: $0 }

TypeDeclarationModifier
"declare" NonIdContinue
Export
( Export _? )? ( Declare _? ) TypeLexicalDeclaration
( Export _? )? ( Declare _? )? TypeDeclarationRest -> { ts: true, children: $0 }

TypeDeclarationRest
TypeKeyword TrailingComment* IdentifierName TypeParameters? __ Equals __ Type
Interface TrailingComment* IdentifierName TypeParameters? InterfaceExtendsClause? InterfaceBlock
Namespace TrailingComment* IdentifierName NamespaceBlock
FunctionSignature
STRd6 marked this conversation as resolved.
Show resolved Hide resolved

TypeLexicalDeclaration
STRd6 marked this conversation as resolved.
Show resolved Hide resolved
__ !( Namespace ) LetOrConst TypeDeclarationBinding ( CommaDelimiter __ TypeDeclarationBinding )*
STRd6 marked this conversation as resolved.
Show resolved Hide resolved

TypeDeclarationBinding
( BindingPattern / BindingIdentifier ) TypeSuffix?

InterfaceExtendsClause
ExtendsToken InterfaceExtendsTarget

Expand Down
8 changes: 8 additions & 0 deletions test/types/type-declaration.civet
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,11 @@ describe "[TS] type declaration", ->
---
const foo: readonly string[] = [ "foo", "bar" ]
"""

testCase """
declare
---
declare const {a, b}: any, {c, d}: any
---
declare const {a, b}: any, {c, d}: any
"""
STRd6 marked this conversation as resolved.
Show resolved Hide resolved