Merge pull request #5422 from weswigham/const-enum-deprocdessing

Const enum deconst'ing
This commit is contained in:
Wesley Wigham 2015-10-28 17:01:39 -07:00
commit d3b95d2e23
5 changed files with 17 additions and 15 deletions

View file

@ -452,6 +452,8 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
// Stanalone/web definition file using global 'ts' namespace
jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true});
var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString();
definitionFileContents = definitionFileContents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, '$1$2enum $3 {$4');
fs.writeFileSync(standaloneDefinitionsFile, definitionFileContents);
// Official node package definition file, pointed to by 'typings' in package.json
// Created by appending 'export = ts;' at the end of the standalone file to turn it into an external module

View file

@ -57,5 +57,5 @@ function compile(fileNames, options) {
exports.compile = compile;
compile(process.argv.slice(2), {
noEmitOnError: true, noImplicitAny: true,
target: 1 /* ES5 */, module: 1 /* CommonJS */
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
});

View file

@ -75,28 +75,28 @@ function delint(sourceFile) {
delintNode(sourceFile);
function delintNode(node) {
switch (node.kind) {
case 199 /* ForStatement */:
case 200 /* ForInStatement */:
case 198 /* WhileStatement */:
case 197 /* DoStatement */:
if (node.statement.kind !== 192 /* Block */) {
case ts.SyntaxKind.ForStatement:
case ts.SyntaxKind.ForInStatement:
case ts.SyntaxKind.WhileStatement:
case ts.SyntaxKind.DoStatement:
if (node.statement.kind !== ts.SyntaxKind.Block) {
report(node, "A looping statement's contents should be wrapped in a block body.");
}
break;
case 196 /* IfStatement */:
case ts.SyntaxKind.IfStatement:
var ifStatement = node;
if (ifStatement.thenStatement.kind !== 192 /* Block */) {
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
}
if (ifStatement.elseStatement &&
ifStatement.elseStatement.kind !== 192 /* Block */ &&
ifStatement.elseStatement.kind !== 196 /* IfStatement */) {
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
}
break;
case 181 /* BinaryExpression */:
case ts.SyntaxKind.BinaryExpression:
var op = node.operatorToken.kind;
if (op === 30 /* EqualsEqualsToken */ || op == 31 /* ExclamationEqualsToken */) {
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
report(node, "Use '===' and '!=='.");
}
break;
@ -112,7 +112,7 @@ exports.delint = delint;
var fileNames = process.argv.slice(2);
fileNames.forEach(function (fileName) {
// Parse a file
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), 2 /* ES6 */, /*setParentNodes */ true);
var sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
// delint it
delint(sourceFile);
});

View file

@ -24,5 +24,5 @@ console.log(JSON.stringify(result));
*/
var ts = require("typescript");
var source = "let x: string = 'string'";
var result = ts.transpile(source, { module: 1 /* CommonJS */ });
var result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
console.log(JSON.stringify(result));

View file

@ -181,4 +181,4 @@ function watch(rootFileNames, options) {
var currentDirectoryFiles = fs.readdirSync(process.cwd()).
filter(function (fileName) { return fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"; });
// Start the watcher
watch(currentDirectoryFiles, { module: 1 /* CommonJS */ });
watch(currentDirectoryFiles, { module: ts.ModuleKind.CommonJS });