Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit ccc0450

Browse files
committed
fix enum export by upgrading closure compiler
If you wrote "export enum ...", the generated ES6 JavaScript would fail to compile in the Closure compiler. I tracked this down to a bug that was fixed in the upstream Closure compiler, so to fix this I had to make us use a newer version of the upstream compiler. To use a newer version of the upstream compiler, I removed one of our indirection layers: we previously used the 'closure-compiler' npm library which pulled in 'google-closure-compiler', but now the latter module exposes a simple API so it's easy enough to just use it directly. Fixes issue #50.
1 parent 3f7e8f7 commit ccc0450

8 files changed

Lines changed: 57 additions & 26 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"devDependencies": {
1515
"chai": "^2.1.1",
1616
"clang-format": "1.0.33",
17-
"closure-compiler": "^0.2.12",
17+
"google-closure-compiler": "^20151216.2.0",
1818
"gulp": "^3.8.11",
1919
"gulp-clang-format": "^1.0.22",
2020
"gulp-mocha": "^2.0.0",

test/closure-compiler.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/e2e_test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import * as ts from 'typescript';
44
import {expect} from 'chai';
5-
import {CompileOptions, compile} from 'closure-compiler';
5+
import * as closure from 'google-closure-compiler';
66

77
import {goldenTests} from './test_support';
88

@@ -11,15 +11,20 @@ export function checkClosureCompile(jsFiles: string[], done: (err: Error) => voi
1111
var total = jsFiles.length;
1212
if (!total) throw new Error('No JS files in ' + JSON.stringify(jsFiles));
1313

14-
var CLOSURE_COMPILER_OPTS: CompileOptions = {
14+
var CLOSURE_COMPILER_OPTS: closure.CompileOptions = {
1515
'checks-only': true,
1616
'jscomp_error': 'checkTypes',
1717
'js': jsFiles,
18-
'language_in': 'ECMASCRIPT6_STRICT'
18+
'language_in': 'ECMASCRIPT6_STRICT',
1919
};
2020

21-
compile(null, CLOSURE_COMPILER_OPTS, (err, stdout, stderr) => {
21+
var compiler = new closure.compiler(CLOSURE_COMPILER_OPTS);
22+
compiler.run((exitCode, stdout, stderr) => {
2223
console.log('Closure compilation:', total, 'done after', Date.now() - startTime, 'ms');
24+
let err: Error = null;
25+
if (exitCode != 0) {
26+
err = new Error(stderr);
27+
}
2328
done(err);
2429
});
2530
}

test/google-closure-compiler.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module 'google-closure-compiler' {
2+
type CompileOptions = {[key: string]: string[] | string | boolean};
3+
interface Compiler {
4+
run(callback: (exitCode: number, stdout: string, stderr: string) => void): void;
5+
}
6+
export var compiler: { new (opts: CompileOptions): Compiler; }
7+
}

test_files/enum.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
enum FooEnum {XYZ, PI = 3.14159}
1+
enum EnumTest1 {XYZ, PI = 3.14159}
2+
3+
// This additional exported enum is here to exercise the fix for issue #51.
4+
export enum EnumTest2 {XYZ, PI = 3.14159}

test_files/es6/enum.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
/** @typedef {number} */
2-
var FooEnum;
3-
(function (FooEnum) {
4-
FooEnum[FooEnum["XYZ"] = 0] = "XYZ";
5-
FooEnum[FooEnum["PI"] = 3.14159] = "PI";
6-
})(FooEnum || (FooEnum = {}));
7-
/** @type {FooEnum} */
8-
FooEnum.XYZ = 0;
9-
/** @type {FooEnum} */
10-
FooEnum.PI = 3.14159;
2+
var EnumTest1;
3+
(function (EnumTest1) {
4+
EnumTest1[EnumTest1["XYZ"] = 0] = "XYZ";
5+
EnumTest1[EnumTest1["PI"] = 3.14159] = "PI";
6+
})(EnumTest1 || (EnumTest1 = {}));
7+
/** @type {EnumTest1} */
8+
EnumTest1.XYZ = 0;
9+
/** @type {EnumTest1} */
10+
EnumTest1.PI = 3.14159;
11+
/** @typedef {number} */
12+
// This additional exported enum is here to exercise the fix for issue #51.
13+
export var EnumTest2;
14+
(function (EnumTest2) {
15+
EnumTest2[EnumTest2["XYZ"] = 0] = "XYZ";
16+
EnumTest2[EnumTest2["PI"] = 3.14159] = "PI";
17+
})(EnumTest2 || (EnumTest2 = {}));
18+
/** @type {EnumTest2} */
19+
EnumTest2.XYZ = 0;
20+
/** @type {EnumTest2} */
21+
EnumTest2.PI = 3.14159;

test_files/sickle/enum.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
/** @typedef {number} */
2-
enum FooEnum {XYZ, PI = 3.14159}
3-
/** @type {FooEnum} */
4-
(<any>FooEnum).XYZ = 0;
5-
/** @type {FooEnum} */
6-
(<any>FooEnum).PI = 3.14159;
2+
enum EnumTest1 {XYZ, PI = 3.14159}
3+
/** @type {EnumTest1} */
4+
(<any>EnumTest1).XYZ = 0;
5+
/** @type {EnumTest1} */
6+
(<any>EnumTest1).PI = 3.14159;
7+
/** @typedef {number} */
8+
9+
10+
// This additional exported enum is here to exercise the fix for issue #51.
11+
export enum EnumTest2 {XYZ, PI = 3.14159}
12+
/** @type {EnumTest2} */
13+
(<any>EnumTest2).XYZ = 0;
14+
/** @type {EnumTest2} */
15+
(<any>EnumTest2).PI = 3.14159;
16+

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"files": [
88
"src/sickle.ts",
99
"test/sickle_test.ts",
10-
"test/closure-compiler.d.ts",
10+
"test/google-closure-compiler.d.ts",
1111
"typings/tsd.d.ts"
1212
]
1313
}

0 commit comments

Comments
 (0)