From 4473aff6ea196c66e5095969bd445aa9a1f11c48 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Sat, 7 May 2016 15:21:25 -0600 Subject: [PATCH] Add flags argument and switch to amd modules by default. See https://github.com/Microsoft/TypeScript/issues/1544 for more information on why --out was unacceptable with modules. --- examples/walkthrough/flags/BUILD | 19 +++++++++++++++++++ examples/walkthrough/flags/animal.ts | 8 ++++++++ examples/walkthrough/flags/main.ts | 17 +++++++++++++++++ typescript/def.bzl | 4 ++++ typescript/run.sh | 2 +- 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 examples/walkthrough/flags/BUILD create mode 100644 examples/walkthrough/flags/animal.ts create mode 100644 examples/walkthrough/flags/main.ts diff --git a/examples/walkthrough/flags/BUILD b/examples/walkthrough/flags/BUILD new file mode 100644 index 0000000..9b47f9b --- /dev/null +++ b/examples/walkthrough/flags/BUILD @@ -0,0 +1,19 @@ +load("//typescript:def.bzl", "ts_binary", "ts_library") + +ts_library( + name = "lib", + srcs = [ + "animal.ts", + "main.ts", + ] +) + +ts_binary( + name = "flags", + flags = [ + "--noImplicitAny", + ], + deps = [ + ":lib", + ] +) diff --git a/examples/walkthrough/flags/animal.ts b/examples/walkthrough/flags/animal.ts new file mode 100644 index 0000000..aefc74d --- /dev/null +++ b/examples/walkthrough/flags/animal.ts @@ -0,0 +1,8 @@ +// Sample inheritance in typescript. +export default class { + constructor(public name: string) { } + + sound(sound: string) { + return this.name + " goes " + sound; + } +} diff --git a/examples/walkthrough/flags/main.ts b/examples/walkthrough/flags/main.ts new file mode 100644 index 0000000..cbcf93c --- /dev/null +++ b/examples/walkthrough/flags/main.ts @@ -0,0 +1,17 @@ +// Sample inheritance in typescript. +import Animal from './animal' + +module Rescue { + export class Dog extends Animal { + constructor(name: string) { + super(name); + } + + sound() { + return "My dog " + super.sound("bark!"); + } + } +} + +let c = new Rescue.Dog("Colby"); +c.sound(); diff --git a/typescript/def.bzl b/typescript/def.bzl index 53e8d16..a3e69ed 100644 --- a/typescript/def.bzl +++ b/typescript/def.bzl @@ -20,6 +20,9 @@ def ts_binary_impl(ctx): inputs=files, outputs=[output], executable=ctx.executable.tsc_, + env={ + "FLAGS": ' '.join(ctx.attr.flags), + }, arguments=["%s" % (output.path)] + \ ["%s" % x.path for x in files]) @@ -40,6 +43,7 @@ ts_binary = rule( executable=True), "deps": attr.label_list(allow_files=True), "srcs": attr.label_list(allow_files=ts_filetype), + "flags": attr.string_list(), }, outputs = { "out": "%{name}.js" diff --git a/typescript/run.sh b/typescript/run.sh index ba5898c..24dd1a8 100755 --- a/typescript/run.sh +++ b/typescript/run.sh @@ -21,5 +21,5 @@ for var in "$@"; do args+=("$(pwd)/${var}") done -$NAR exec "--out ${args[*]}" +$NAR exec "--module amd ${FLAGS} --outFile ${args[*]}" touch .tsc_unlock