Skip to content

Commit

Permalink
Merge pull request #38 from jonas/test-and-import-improvements
Browse files Browse the repository at this point in the history
Test and import improvements
  • Loading branch information
sjrd committed Sep 9, 2017
2 parents 1a5736c + bd2e2f4 commit 9a35581
Show file tree
Hide file tree
Showing 18 changed files with 271 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ scala: 2.12.3

jdk: oraclejdk8

script: sbt ++$TRAVIS_SCALA_VERSION test
script: sbt ++$TRAVIS_SCALA_VERSION samples/compile test

before_cache:
# See http://www.scala-sbt.org/0.13/docs/Travis-CI-with-sbt.html
Expand Down
43 changes: 22 additions & 21 deletions build.sbt
@@ -1,23 +1,24 @@
scalaVersion := "2.12.3"
inThisBuild(Def.settings(
organization := "org.scalajs.tools",
version := "0.1-SNAPSHOT",
scalaVersion := "2.12.3",
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature",
"-encoding", "utf8"
)
))

name := "TypeScript importer for Scala.js"
val `scala-js-ts-importer` = project.in(file("."))
.settings(
description := "TypeScript importer for Scala.js",
mainClass := Some("org.scalajs.tools.tsimporter.Main"),
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6",
"org.scalatest" %% "scalatest" % "3.0.4" % Test
)
)

version := "0.1-SNAPSHOT"

mainClass := Some("org.scalajs.tools.tsimporter.Main")

libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6",
"org.scalatest" %% "scalatest" % "3.0.4" % Test
)

organization := "org.scalajs.tools"

scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature",
"-encoding", "utf8"
)

fork in Test := true
val samples = project
.enablePlugins(ScalaJSPlugin)
2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=0.13.9
sbt.version=1.0.1
1 change: 1 addition & 0 deletions project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20")
17 changes: 17 additions & 0 deletions samples/jsglobal.ts
@@ -0,0 +1,17 @@
export class Point {
constructor(x: number, y: number);
readonly x: number;
readonly y: number;
static isPoint(thing: any): boolean;
}

declare module nested {
type Line = Array<Point>;

export class Circle {
constructor(center: Point, radius: number);
readonly center: Point;
readonly radius: number;
static isCirce(thing: any): boolean;
}
}
46 changes: 46 additions & 0 deletions samples/jsglobal.ts.scala
@@ -0,0 +1,46 @@

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

package importedjs {

@js.native
@JSGlobal
class Point protected () extends js.Object {
def this(x: Double, y: Double) = this()
def x: Double = js.native
def y: Double = js.native
}

@js.native
@JSGlobal
object Point extends js.Object {
def isPoint(thing: js.Any): Boolean = js.native
}

package nested {

@js.native
@JSGlobal("nested.Circle")
class Circle protected () extends js.Object {
def this(center: Point, radius: Double) = this()
def center: Point = js.native
def radius: Double = js.native
}

@js.native
@JSGlobal("nested.Circle")
object Circle extends js.Object {
def isCirce(thing: js.Any): Boolean = js.native
}

@js.native
@JSGlobal("nested")
object Nested extends js.Object {
type Line = js.Array[Point]
}

}

}
12 changes: 3 additions & 9 deletions src/test/resources/samples/modifiers.ts → samples/modifiers.ts
@@ -1,7 +1,8 @@
declare module monaco {
declare module modifiers {

const id: string;
export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black';

interface IEvent<T> {}

export class Emitter<T> {
constructor();
Expand Down Expand Up @@ -31,11 +32,4 @@ declare module monaco {
readonly path: string;
}

export interface IEditorOptions {
ariaLabel?: string;
rulers?: number[];
selectionClipboard?: boolean;
lineNumbers?: 'on' | 'off' | 'relative' | ((lineNumber: number) => string);
readable?: 'yes' | boolean | 'restricted';
}
}
Expand Up @@ -5,52 +5,46 @@ import js.|

package importedjs {

package monaco {
package modifiers {

@js.native
@JSGlobal("monaco.Emitter")
trait IEvent[T] extends js.Object {
}

@js.native
@JSGlobal("modifiers.Emitter")
class Emitter[T] extends js.Object {
def event: IEvent[T] = js.native
def fire(event: T = ???): Unit = js.native
def dispose(): Unit = js.native
}

@js.native
@JSGlobal("monaco.EditorType")
@JSGlobal("modifiers.EditorType")
object EditorType extends js.Object {
var ICodeEditor: String = js.native
var IDiffEditor: String = js.native
}

@js.native
@JSGlobal("monaco.Uri")
@JSGlobal("modifiers.Uri")
class Uri extends js.Object {
def scheme: String = js.native
def authority: String = js.native
def path: String = js.native
}

@js.native
@JSGlobal("monaco.Uri")
@JSGlobal("modifiers.Uri")
object Uri extends js.Object {
def isUri(thing: js.Any): Boolean = js.native
def parse(value: String): Uri = js.native
}

@js.native
trait IEditorOptions extends js.Object {
var ariaLabel: String = js.native
var rulers: js.Array[Double] = js.native
var selectionClipboard: Boolean = js.native
var lineNumbers: String | js.Function1[Double, String] = js.native
var readable: String | Boolean = js.native
}

@js.native
@JSGlobal("monaco")
object Monaco extends js.Object {
@JSGlobal("modifiers")
object Modifiers extends js.Object {
val id: String = js.native
type BuiltinTheme = String
val CursorMoveByUnit: js.Any = js.native
}

Expand Down
24 changes: 24 additions & 0 deletions samples/overrides.ts
@@ -0,0 +1,24 @@
declare module overrides {

export class A {
equals(other: A): boolean;
clone(): A;
toString(): string;
}

interface BLike {
toString(): string;
}

export class B extends BLike {
equals(other: any): boolean;
clone(): BLike;
toString(): string;
}

interface C {
equals(other: any): boolean;
clone(): C;
toString(): string;
}
}
40 changes: 40 additions & 0 deletions samples/overrides.ts.scala
@@ -0,0 +1,40 @@

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

package importedjs {

package overrides {

@js.native
@JSGlobal("overrides.A")
class A extends js.Object {
def equals(other: A): Boolean = js.native
override def clone(): A = js.native
override def toString(): String = js.native
}

@js.native
trait BLike extends js.Object {
override def toString(): String = js.native
}

@js.native
@JSGlobal("overrides.B")
class B extends BLike {
def equals(other: js.Any): Boolean = js.native
override def clone(): BLike = js.native
override def toString(): String = js.native
}

@js.native
trait C extends js.Object {
def equals(other: js.Any): Boolean = js.native
override def clone(): C = js.native
override def toString(): String = js.native
}

}

}
12 changes: 12 additions & 0 deletions samples/stringlit.ts
@@ -0,0 +1,12 @@
declare module stringlit {

export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black';

export interface IEditorOptions {
ariaLabel?: string;
rulers?: number[];
selectionClipboard?: boolean;
lineNumbers?: 'on' | 'off' | 'relative' | ((lineNumber: number) => string);
readable?: 'yes' | boolean | 'restricted';
}
}
27 changes: 27 additions & 0 deletions samples/stringlit.ts.scala
@@ -0,0 +1,27 @@

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

package importedjs {

package stringlit {

@js.native
trait IEditorOptions extends js.Object {
var ariaLabel: String = js.native
var rulers: js.Array[Double] = js.native
var selectionClipboard: Boolean = js.native
var lineNumbers: String | js.Function1[Double, String] = js.native
var readable: String | Boolean = js.native
}

@js.native
@JSGlobal("stringlit")
object Stringlit extends js.Object {
type BuiltinTheme = String
}

}

}
10 changes: 10 additions & 0 deletions samples/then.ts
@@ -0,0 +1,10 @@
declare module then {

interface Thenable<T> {
then<TResult>(
onfulfilled?: (value: T) => TResult | Thenable<TResult>,
onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
}

class then {}
}
22 changes: 22 additions & 0 deletions samples/then.ts.scala
@@ -0,0 +1,22 @@

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

package importedjs {

package `then` {

@js.native
trait Thenable[T] extends js.Object {
def `then`[TResult](onfulfilled: js.Function1[T, TResult | Thenable[TResult]] = ???, onrejected: js.Function1[js.Any, TResult | Thenable[TResult]] = ???): Thenable[TResult] = js.native
}

@js.native
@JSGlobal("then.then")
class `then` extends js.Object {
}

}

}
4 changes: 2 additions & 2 deletions src/main/scala/org/scalajs/tools/tsimporter/Utils.scala
Expand Up @@ -21,8 +21,8 @@ object Utils {
val isScalaKeyword: Set[String] = Set(
"abstract", "case", "class", "catch", "def", "do", "else", "extends",
"false", "final", "finally", "for", "forSome", "if", "implicit",
"import", "lazy", "match", "new", "null", "object", "override",
"package", "private", "protected", "return", "sealed", "super", "this",
"import", "lazy", "match", "new", "null", "object", "override", "package",
"private", "protected", "return", "sealed", "super", "then", "this",
"throw", "trait", "true", "try", "type", "val", "var", "with", "while",
"yield", ".", "_", ":", "=", "=>", "<-", "<:", "<%", ">:", "#", "@")

Expand Down

0 comments on commit 9a35581

Please sign in to comment.