Skip to content

Allow numeric literal as property name #55

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

Merged
merged 4 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions samples/objectlit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare var ObjectType: { name: string; age: number };

declare var NumericKeyObjectType: { 0: number; 1: number; 2.1: number };
23 changes: 23 additions & 0 deletions samples/objectlit.d.ts.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import scala.scalajs.js
import js.annotation._
import js.|

package objectlit {

@js.native
@JSGlobal
object ObjectType extends js.Object {
var name: String = js.native
var age: Double = js.native
}

@js.native
@JSGlobal
object NumericKeyObjectType extends js.Object {
var `0`: Double = js.native
var `1`: Double = js.native
var `2.1`: Double = js.native
}

}
10 changes: 7 additions & 3 deletions src/main/scala/org/scalajs/tools/tsimporter/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,15 @@ object Trees {

case class BooleanLiteral(value: Boolean) extends Literal

sealed trait NumberLiteral extends Literal
sealed trait NumberLiteral extends Literal with PropertyName

case class IntLiteral(value: Int) extends NumberLiteral
case class IntLiteral(value: Int) extends NumberLiteral {
override def name = value.toString
}

case class DoubleLiteral(value: Double) extends NumberLiteral
case class DoubleLiteral(value: Double) extends NumberLiteral {
override def name = value.toString
}

case class StringLiteral(value: String) extends Literal with PropertyName {
override def name = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class TSDefParser extends StdTokenParsers with ImplicitConversions {
})

lazy val propertyName: Parser[PropertyName] =
identifier | stringLiteral
identifier | stringLiteral | numberLiteral

lazy val stringLiteral: Parser[StringLiteral] =
stringLit ^^ StringLiteral
Expand Down