Skip to content

Commit 975e821

Browse files
committed
Fixes the various TypeErrors coming from some transforms.
1 parent bcb180a commit 975e821

8 files changed

Lines changed: 353 additions & 51 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tests/baselines/rwc/*
1313
tests/baselines/test262/*
1414
tests/baselines/reference/projectOutput/*
1515
tests/baselines/local/projectOutput/*
16+
tests/baselines/reference/testresults.tap
1617
tests/services/baselines/prototyping/local/*
1718
tests/services/browser/typescriptServices.js
1819
scripts/configureNightly.js

Jakefile.js

Lines changed: 214 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var os = require("os");
55
var path = require("path");
66
var child_process = require("child_process");
77
var Linter = require("tslint");
8+
var readline = require("readline");
89

910
// Variables
1011
var compilerDirectory = "src/compiler/";
@@ -673,9 +674,14 @@ function cleanTestDirs() {
673674
}
674675

675676
// used to pass data from jake command line directly to run.js
676-
function writeTestConfigFile(tests, light, testConfigFile) {
677+
function writeTestConfigFile(testConfigFile, tests, light, stackTraceLimit) {
677678
console.log('Running test(s): ' + tests);
678-
var testConfigContents = JSON.stringify({ test: [tests], light: light });
679+
var testConfig = { test: [tests], light: light };
680+
if (/^(\d+|full)$/.test(stackTraceLimit)) {
681+
testConfig.stackTraceLimit = stackTraceLimit;
682+
}
683+
684+
var testConfigContents = JSON.stringify(testConfig);
679685
fs.writeFileSync('test.config', testConfigContents);
680686
}
681687

@@ -685,6 +691,124 @@ function deleteTemporaryProjectOutput() {
685691
}
686692
}
687693

694+
function runTestsAndWriteOutput(file) {
695+
cleanTestDirs();
696+
var tests = process.env.test || process.env.tests || process.env.t;
697+
var light = process.env.light || false;
698+
var testConfigFile = 'test.config';
699+
if (fs.existsSync(testConfigFile)) {
700+
fs.unlinkSync(testConfigFile);
701+
}
702+
703+
if (tests || light) {
704+
writeTestConfigFile(testConfigFile, tests, light, 10);
705+
}
706+
707+
if (tests && tests.toLocaleLowerCase() === "rwc") {
708+
testTimeout = 100000;
709+
}
710+
711+
var args = [];
712+
args.push("-R", "TAP");
713+
args.push("--no-colors");
714+
args.push("-t", testTimeout);
715+
if (tests) {
716+
args.push("-g", '"' + tests + '"');
717+
}
718+
args.push(run);
719+
720+
var cmd = "mocha " + args.join(" ");
721+
console.log(cmd);
722+
var ex = jake.createExec([cmd], { windowsVerbatimArguments: true });
723+
var out = fs.createWriteStream(file);
724+
var tapRange = /^(\d+)\.\.(\d+)(?:$|\r\n?|\n)/;
725+
var tapOk = /^ok\s/;
726+
var tapNotOk = /^not\sok/;
727+
var tapComment = /^#/;
728+
var typeError = /^\s+TypeError:/;
729+
var progress = new ProgressBar("Running tests...");
730+
var expectedTestCount = 0;
731+
var testCount = 0;
732+
var failureCount = 0;
733+
var successCount = 0;
734+
var comments = [];
735+
var typeErrorCount = 0;
736+
737+
ex.addListener("stdout", function (output) {
738+
var m = tapRange.exec(output);
739+
if (m) {
740+
expectedTestCount = parseInt(m[2]);
741+
return;
742+
}
743+
744+
out.write(output);
745+
746+
if (tapOk.test(output)) {
747+
successCount++;
748+
}
749+
else if (tapNotOk.test(output)) {
750+
failureCount++;
751+
}
752+
else {
753+
if (tapComment.test(output)) {
754+
comments.push(output.toString().trim());
755+
}
756+
else if (typeError.test(output)) {
757+
typeErrorCount++;
758+
}
759+
return;
760+
}
761+
762+
testCount++;
763+
764+
var percentComplete = testCount * 100 / expectedTestCount;
765+
updateProgress(percentComplete);
766+
});
767+
768+
function updateProgress(percentComplete) {
769+
progress.update(percentComplete,
770+
/*foregroundColor*/ failureCount > 0
771+
? "red"
772+
: successCount === expectedTestCount
773+
? "green"
774+
: "cyan",
775+
/*backgroundColor*/ "gray"
776+
);
777+
}
778+
779+
ex.addListener("stderr", function (output) {
780+
progress.hide();
781+
process.stderr.write(output.toString().trim() + os.EOL);
782+
progress.show();
783+
});
784+
ex.addListener("cmdEnd", function () {
785+
if (progress.visible) {
786+
updateProgress(100);
787+
process.stdout.write("done." + os.EOL);
788+
}
789+
790+
console.log(comments.join(os.EOL));
791+
deleteTemporaryProjectOutput();
792+
complete();
793+
});
794+
ex.addListener("error", function (e, status) {
795+
if (progress.visible) {
796+
updateProgress(100);
797+
process.stdout.write("done." + os.EOL);
798+
}
799+
800+
console.log(comments.join(os.EOL));
801+
802+
if (typeErrorCount) {
803+
console.log("# type errors: %s", typeErrorCount);
804+
}
805+
806+
deleteTemporaryProjectOutput();
807+
fail("Process exited with code " + status);
808+
});
809+
ex.run();
810+
}
811+
688812
function runConsoleTests(defaultReporter, defaultSubsets) {
689813
cleanTestDirs();
690814
var debug = process.env.debug || process.env.d;
@@ -696,7 +820,7 @@ function runConsoleTests(defaultReporter, defaultSubsets) {
696820
}
697821

698822
if (tests || light) {
699-
writeTestConfigFile(tests, light, testConfigFile);
823+
writeTestConfigFile(testConfigFile, tests, light);
700824
}
701825

702826
if (tests && tests.toLocaleLowerCase() === "rwc") {
@@ -749,6 +873,10 @@ task("runtests", ["build-rules", "tests", builtLocalDirectory], function() {
749873
runConsoleTests('mocha-fivemat-progress-reporter', []);
750874
}, {async: true});
751875

876+
task("runtests-file", ["build-rules", "tests", builtLocalDirectory], function () {
877+
runTestsAndWriteOutput("tests/baselines/local/testresults.tap");
878+
}, { async: true });
879+
752880
desc("Generates code coverage data via instanbul");
753881
task("generate-code-coverage", ["tests", builtLocalDirectory], function () {
754882
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run;
@@ -780,7 +908,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFi
780908
fs.unlinkSync(testConfigFile);
781909
}
782910
if(tests || light) {
783-
writeTestConfigFile(tests, light, testConfigFile);
911+
writeTestConfigFile(testConfigFile, tests, light);
784912
}
785913

786914
tests = tests ? tests : '';
@@ -1031,3 +1159,85 @@ task("lint-server", ["build-rules"], function() {
10311159
lintWatchFile(lintTargets[i]);
10321160
}
10331161
});
1162+
1163+
function ProgressBar(title) {
1164+
this.title = title;
1165+
}
1166+
ProgressBar.prototype = {
1167+
progressChars: ["\u0020", "\u2591", "\u2592", "\u2593", "\u2588"],
1168+
colors: {
1169+
foreground: {
1170+
black: "\u001b[90m",
1171+
red: "\u001b[91m",
1172+
green: "\u001b[92m",
1173+
yellow: "\u001b[93m",
1174+
blue: "\u001b[94m",
1175+
magenta: "\u001b[95m",
1176+
cyan: "\u001b[96m",
1177+
white: "\u001b[97m",
1178+
gray: "\u001b[37m"
1179+
},
1180+
background: {
1181+
black: "\u001b[40m",
1182+
red: "\u001b[41m",
1183+
green: "\u001b[42m",
1184+
yellow: "\u001b[43m",
1185+
blue: "\u001b[44m",
1186+
magenta: "\u001b[45m",
1187+
cyan: "\u001b[46m",
1188+
white: "\u001b[47m",
1189+
gray: "\u001b[100m"
1190+
},
1191+
reset: "\u001b[0m"
1192+
},
1193+
update: function (percentComplete, foregroundColor, backgroundColor) {
1194+
var progress = "";
1195+
for (var i = 0; i < 100; i += 4) {
1196+
progress += this.progressChars[Math.floor(Math.max(0, Math.min(4, percentComplete - i)))];
1197+
}
1198+
1199+
foregroundColor = foregroundColor && this.colors.foreground[foregroundColor];
1200+
backgroundColor = backgroundColor && this.colors.background[backgroundColor];
1201+
if (foregroundColor || backgroundColor) {
1202+
if (foregroundColor) {
1203+
progress = foregroundColor + progress;
1204+
}
1205+
if (backgroundColor) {
1206+
progress = backgroundColor + progress;
1207+
}
1208+
1209+
progress += this.colors.reset;
1210+
}
1211+
1212+
if (this._lastProgress !== progress || !this.visible) {
1213+
this._print(progress);
1214+
}
1215+
},
1216+
hide: function () {
1217+
if (this.visible) {
1218+
this._savedProgress = this._lastProgress;
1219+
this.clear();
1220+
}
1221+
},
1222+
show: function () {
1223+
if (this._savedProgress && !this.visible) {
1224+
this._print(this._savedProgress);
1225+
this._savedProgress = undefined;
1226+
}
1227+
},
1228+
clear: function () {
1229+
if (this._lastProgress) {
1230+
readline.moveCursor(process.stdout, -process.stdout.columns, 0);
1231+
readline.clearLine(process.stdout, 1);
1232+
this._lastProgress = undefined;
1233+
this.visible = false;
1234+
}
1235+
},
1236+
_print: function (progress) {
1237+
readline.moveCursor(process.stdout, -process.stdout.columns, 0);
1238+
process.stdout.write(this.title ? progress + " " + this.title : progress);
1239+
readline.clearLine(process.stdout, 1);
1240+
this._lastProgress = progress;
1241+
this.visible = true;
1242+
}
1243+
};

src/compiler/core.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,10 @@ namespace ts {
10791079
declare var process: any;
10801080
declare var require: any;
10811081

1082-
const currentAssertionLevel = getDevelopmentMode() === "development"
1083-
? AssertionLevel.Normal
1084-
: AssertionLevel.None;
1082+
let currentAssertionLevel: AssertionLevel;
10851083

10861084
export function shouldAssert(level: AssertionLevel): boolean {
1087-
return currentAssertionLevel >= level;
1085+
return getCurrentAssertionLevel() >= level;
10881086
}
10891087

10901088
export function assert(expression: boolean, message?: string, verboseDebugInfo?: () => string): void {
@@ -1102,15 +1100,21 @@ namespace ts {
11021100
Debug.assert(/*expression*/ false, message);
11031101
}
11041102

1105-
function getDevelopmentMode() {
1106-
return typeof require !== "undefined"
1107-
&& typeof process !== "undefined"
1108-
&& !process.browser
1109-
&& process.nextTick
1110-
&& process.env
1111-
&& process.env.NODE_ENV
1112-
? String(process.env.NODE_ENV).toLowerCase()
1113-
: undefined;
1103+
function getCurrentAssertionLevel() {
1104+
if (currentAssertionLevel !== undefined) {
1105+
return currentAssertionLevel;
1106+
}
1107+
1108+
const developmentMode = sys && /^development$/i.test(sys.getEnvironmentVariable("NODE_ENV"));
1109+
if (developmentMode === undefined) {
1110+
return AssertionLevel.None;
1111+
}
1112+
1113+
currentAssertionLevel = developmentMode
1114+
? AssertionLevel.Normal
1115+
: AssertionLevel.None;
1116+
1117+
return currentAssertionLevel;
11141118
}
11151119
}
11161120

src/compiler/transformers/module/module.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,13 @@ namespace ts {
456456
}
457457

458458
function visitExportAssignment(node: ExportAssignment): VisitResult<Statement> {
459-
if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
460-
const statements: Statement[] = [];
461-
addExportDefault(statements, node.expression, /*location*/ node);
462-
return statements;
459+
if (!node.isExportEquals) {
460+
const original = getOriginalNode(node);
461+
if (nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original)) {
462+
const statements: Statement[] = [];
463+
addExportDefault(statements, node.expression, /*location*/ node);
464+
return statements;
465+
}
463466
}
464467

465468
return undefined;

src/compiler/transformers/module/system.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ namespace ts {
4545

4646
return transformSourceFile;
4747

48-
function onEmitNode(node: Node, emit: (node: Node) => void): void {
49-
exportFunctionForFile = exportFunctionForFileMap[getNodeId(node)];
50-
previousOnEmitNode(node, emit);
51-
exportFunctionForFile = undefined;
52-
}
53-
5448
function transformSourceFile(node: SourceFile) {
5549
if (isExternalModule(node) || compilerOptions.isolatedModules) {
5650
currentSourceFile = node;
@@ -548,11 +542,14 @@ namespace ts {
548542
}
549543

550544
function visitExportAssignment(node: ExportAssignment): Statement {
551-
if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
552-
return createExportStatement(
553-
createLiteral("default"),
554-
node.expression
555-
);
545+
if (!node.isExportEquals) {
546+
const original = getOriginalNode(node);
547+
if (nodeIsSynthesized(original) || resolver.isValueAliasDeclaration(original)) {
548+
return createExportStatement(
549+
createLiteral("default"),
550+
node.expression
551+
);
552+
}
556553
}
557554

558555
return undefined;
@@ -918,6 +915,17 @@ namespace ts {
918915
// Substitutions
919916
//
920917

918+
function onEmitNode(node: Node, emit: (node: Node) => void): void {
919+
if (node.kind === SyntaxKind.SourceFile) {
920+
exportFunctionForFile = exportFunctionForFileMap[getNodeId(node)];
921+
previousOnEmitNode(node, emit);
922+
exportFunctionForFile = undefined;
923+
}
924+
else {
925+
previousOnEmitNode(node, emit);
926+
}
927+
}
928+
921929
/**
922930
* Substitute the expression, if necessary.
923931
*

0 commit comments

Comments
 (0)