From 35d848f0bda676d99954c5c142b651c1838cd224 Mon Sep 17 00:00:00 2001 From: Ahmad Farid Date: Thu, 9 Apr 2015 17:11:42 -0700 Subject: [PATCH] merging --- .../baselines/reference/APISample_compile.js | 66 +++--- tests/baselines/reference/APISample_linter.js | 126 +++++------ .../reference/APISample_transform.js | 30 +-- .../baselines/reference/APISample_watcher.js | 204 +++++++++--------- .../reference/decoratorOnClassMethod11.js | 14 +- .../reference/decoratorOnClassMethod13.types | 4 +- 6 files changed, 222 insertions(+), 222 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 83414abaf6e..f30bd2c21a9 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1,37 +1,37 @@ //// [APISample_compile.ts] - -/* - * Note: This test is a public API sample. The sample sources can be found - at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler - * Please log a "breaking change" issue for any API breaking change affecting this issue - */ - -declare var process: any; -declare var console: any; -declare var os: any; - -import ts = require("typescript"); - -export function compile(fileNames: string[], options: ts.CompilerOptions): void { - var program = ts.createProgram(fileNames, options); - var emitResult = program.emit(); - - var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); - - allDiagnostics.forEach(diagnostic => { - var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); - var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); - }); - - var exitCode = emitResult.emitSkipped ? 1 : 0; - console.log(`Process exiting with code '${exitCode}'.`); - process.exit(exitCode); -} - -compile(process.argv.slice(2), { - noEmitOnError: true, noImplicitAny: true, - target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS + +/* + * Note: This test is a public API sample. The sample sources can be found + at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler + * Please log a "breaking change" issue for any API breaking change affecting this issue + */ + +declare var process: any; +declare var console: any; +declare var os: any; + +import ts = require("typescript"); + +export function compile(fileNames: string[], options: ts.CompilerOptions): void { + var program = ts.createProgram(fileNames, options); + var emitResult = program.emit(); + + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + + allDiagnostics.forEach(diagnostic => { + var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); + }); + + var exitCode = emitResult.emitSkipped ? 1 : 0; + console.log(`Process exiting with code '${exitCode}'.`); + process.exit(exitCode); +} + +compile(process.argv.slice(2), { + noEmitOnError: true, noImplicitAny: true, + target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS }); //// [APISample_compile.js] diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 9e1b4cf6c0d..17061add038 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1,67 +1,67 @@ //// [APISample_linter.ts] - -/* - * Note: This test is a public API sample. The sample sources can be found - at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter - * Please log a "breaking change" issue for any API breaking change affecting this issue - */ - -declare var process: any; -declare var console: any; -declare var readFileSync: any; - -import * as ts from "typescript"; - -export function delint(sourceFile: ts.SourceFile) { - delintNode(sourceFile); - - function delintNode(node: ts.Node) { - switch (node.kind) { - 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 ts.SyntaxKind.IfStatement: - let ifStatement = (node); - 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 !== 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 ts.SyntaxKind.BinaryExpression: - let op = (node).operatorToken.kind; - if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) { - report(node, "Use '===' and '!=='.") - } - break; - } - - ts.forEachChild(node, delintNode); - } - - function report(node: ts.Node, message: string) { - let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart()); - console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`); - } -} - -const fileNames = process.argv.slice(2); -fileNames.forEach(fileName => { - // Parse a file - let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); - - // delint it - delint(sourceFile); + +/* + * Note: This test is a public API sample. The sample sources can be found + at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter + * Please log a "breaking change" issue for any API breaking change affecting this issue + */ + +declare var process: any; +declare var console: any; +declare var readFileSync: any; + +import * as ts from "typescript"; + +export function delint(sourceFile: ts.SourceFile) { + delintNode(sourceFile); + + function delintNode(node: ts.Node) { + switch (node.kind) { + 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 ts.SyntaxKind.IfStatement: + let ifStatement = (node); + 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 !== 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 ts.SyntaxKind.BinaryExpression: + let op = (node).operatorToken.kind; + if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) { + report(node, "Use '===' and '!=='.") + } + break; + } + + ts.forEachChild(node, delintNode); + } + + function report(node: ts.Node, message: string) { + let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart()); + console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`); + } +} + +const fileNames = process.argv.slice(2); +fileNames.forEach(fileName => { + // Parse a file + let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); + + // delint it + delint(sourceFile); }); //// [APISample_linter.js] diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index c38fe2a419b..a7f83f19b5e 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1,19 +1,19 @@ //// [APISample_transform.ts] - -/* - * Note: This test is a public API sample. The sample sources can be found - at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function - * Please log a "breaking change" issue for any API breaking change affecting this issue - */ - -declare var console: any; - -import * as ts from "typescript"; - -const source = "let x: string = 'string'"; - -let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS }); - + +/* + * Note: This test is a public API sample. The sample sources can be found + at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function + * Please log a "breaking change" issue for any API breaking change affecting this issue + */ + +declare var console: any; + +import * as ts from "typescript"; + +const source = "let x: string = 'string'"; + +let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS }); + console.log(JSON.stringify(result)); //// [APISample_transform.js] diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 704d36b6954..e2ab4e135dd 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1,106 +1,106 @@ //// [APISample_watcher.ts] - -/* - * Note: This test is a public API sample. The sample sources can be found - at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#incremental-build-support-using-the-language-services - * Please log a "breaking change" issue for any API breaking change affecting this issue - */ - -declare var process: any; -declare var console: any; -declare var fs: any; -declare var path: any; - -import * as ts from "typescript"; - -function watch(rootFileNames: string[], options: ts.CompilerOptions) { - const files: ts.Map<{ version: number }> = {}; - - // initialize the list of files - rootFileNames.forEach(fileName => { - files[fileName] = { version: 0 }; - }); - - // Create the language service host to allow the LS to communicate with the host - const servicesHost: ts.LanguageServiceHost = { - getScriptFileNames: () => rootFileNames, - getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(), - getScriptSnapshot: (fileName) => { - if (!fs.existsSync(fileName)) { - return undefined; - } - - return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()); - }, - getCurrentDirectory: () => process.cwd(), - getCompilationSettings: () => options, - getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), - }; - - // Create the language service files - const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()) - - // Now let's watch the files - rootFileNames.forEach(fileName => { - // First time around, emit all files - emitFile(fileName); - - // Add a watch on the file to handle next change - fs.watchFile(fileName, - { persistent: true, interval: 250 }, - (curr, prev) => { - // Check timestamp - if (+curr.mtime <= +prev.mtime) { - return; - } - - // Update the version to signal a change in the file - files[fileName].version++; - - // write the changes to disk - emitFile(fileName); - }); - }); - - function emitFile(fileName: string) { - let output = services.getEmitOutput(fileName); - - if (!output.emitSkipped) { - console.log(`Emitting ${fileName}`); - } - else { - console.log(`Emitting ${fileName} failed`); - logErrors(fileName); - } - - output.outputFiles.forEach(o => { - fs.writeFileSync(o.name, o.text, "utf8"); - }); - } - - function logErrors(fileName: string) { - let allDiagnostics = services.getCompilerOptionsDiagnostics() - .concat(services.getSyntacticDiagnostics(fileName)) - .concat(services.getSemanticDiagnostics(fileName)); - - allDiagnostics.forEach(diagnostic => { - let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); - if (diagnostic.file) { - let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); - console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); - } - else { - console.log(` Error: ${message}`); - } - }); - } -} - -// Initialize files constituting the program as all .ts files in the current directory -const currentDirectoryFiles = fs.readdirSync(process.cwd()). - filter(fileName=> fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"); - -// Start the watcher + +/* + * Note: This test is a public API sample. The sample sources can be found + at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#incremental-build-support-using-the-language-services + * Please log a "breaking change" issue for any API breaking change affecting this issue + */ + +declare var process: any; +declare var console: any; +declare var fs: any; +declare var path: any; + +import * as ts from "typescript"; + +function watch(rootFileNames: string[], options: ts.CompilerOptions) { + const files: ts.Map<{ version: number }> = {}; + + // initialize the list of files + rootFileNames.forEach(fileName => { + files[fileName] = { version: 0 }; + }); + + // Create the language service host to allow the LS to communicate with the host + const servicesHost: ts.LanguageServiceHost = { + getScriptFileNames: () => rootFileNames, + getScriptVersion: (fileName) => files[fileName] && files[fileName].version.toString(), + getScriptSnapshot: (fileName) => { + if (!fs.existsSync(fileName)) { + return undefined; + } + + return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()); + }, + getCurrentDirectory: () => process.cwd(), + getCompilationSettings: () => options, + getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), + }; + + // Create the language service files + const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()) + + // Now let's watch the files + rootFileNames.forEach(fileName => { + // First time around, emit all files + emitFile(fileName); + + // Add a watch on the file to handle next change + fs.watchFile(fileName, + { persistent: true, interval: 250 }, + (curr, prev) => { + // Check timestamp + if (+curr.mtime <= +prev.mtime) { + return; + } + + // Update the version to signal a change in the file + files[fileName].version++; + + // write the changes to disk + emitFile(fileName); + }); + }); + + function emitFile(fileName: string) { + let output = services.getEmitOutput(fileName); + + if (!output.emitSkipped) { + console.log(`Emitting ${fileName}`); + } + else { + console.log(`Emitting ${fileName} failed`); + logErrors(fileName); + } + + output.outputFiles.forEach(o => { + fs.writeFileSync(o.name, o.text, "utf8"); + }); + } + + function logErrors(fileName: string) { + let allDiagnostics = services.getCompilerOptionsDiagnostics() + .concat(services.getSyntacticDiagnostics(fileName)) + .concat(services.getSemanticDiagnostics(fileName)); + + allDiagnostics.forEach(diagnostic => { + let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); + if (diagnostic.file) { + let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); + } + else { + console.log(` Error: ${message}`); + } + }); + } +} + +// Initialize files constituting the program as all .ts files in the current directory +const currentDirectoryFiles = fs.readdirSync(process.cwd()). + filter(fileName=> fileName.length >= 3 && fileName.substr(fileName.length - 3, 3) === ".ts"); + +// Start the watcher watch(currentDirectoryFiles, { module: ts.ModuleKind.CommonJS }); //// [APISample_watcher.js] diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js index 71d4298f02c..f8276de2fe3 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.js +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -1,11 +1,11 @@ //// [decoratorOnClassMethod11.ts] -module M { - class C { - decorator(target: Object, key: string): void { } - - @this.decorator - method() { } - } +module M { + class C { + decorator(target: Object, key: string): void { } + + @this.decorator + method() { } + } } //// [decoratorOnClassMethod11.js] diff --git a/tests/baselines/reference/decoratorOnClassMethod13.types b/tests/baselines/reference/decoratorOnClassMethod13.types index 8c34805792f..1390f5750e6 100644 --- a/tests/baselines/reference/decoratorOnClassMethod13.types +++ b/tests/baselines/reference/decoratorOnClassMethod13.types @@ -14,8 +14,8 @@ class C { >C : C @dec ["1"]() { } ->dec : unknown +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor @dec ["b"]() { } ->dec : unknown +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor }