├── LICENCE
├── tests
├── tse
│ ├── 3iwilllogargs.ts
│ ├── test.bat
│ ├── 2iwillfork.ts
│ ├── 1start.ts
│ └── tsconfig.json
└── grunt
│ ├── fail
│ ├── tsconfig.json
│ ├── fail.js
│ └── fail.ts
│ └── pass
│ ├── tsconfig.json
│ ├── pass.ts
│ └── pass.js
├── .npmignore
├── quick.sh
├── src
├── services
│ ├── refactors
│ │ └── refactors.ts
│ ├── formatting
│ │ ├── ruleFlag.ts
│ │ ├── ruleAction.ts
│ │ ├── formattingRequestKind.ts
│ │ ├── references.ts
│ │ ├── rule.ts
│ │ ├── ruleOperation.ts
│ │ ├── ruleOperationContext.ts
│ │ ├── ruleDescriptor.ts
│ │ ├── rulesProvider.ts
│ │ ├── formattingContext.ts
│ │ ├── tokenRange.ts
│ │ └── rulesMap.ts
│ ├── codefixes
│ │ ├── fixes.ts
│ │ ├── fixForgottenThisPropertyAccess.ts
│ │ ├── fixConstructorForDerivedNeedSuperCall.ts
│ │ ├── fixExtendsInterfaceBecomesImplements.ts
│ │ ├── fixSpelling.ts
│ │ ├── fixClassSuperMustPrecedeThisAccess.ts
│ │ ├── fixClassDoesntImplementInheritedAbstractMember.ts
│ │ ├── fixClassIncorrectlyImplementsInterface.ts
│ │ └── disableJsDiagnostics.ts
│ ├── transform.ts
│ ├── codeFixProvider.ts
│ ├── goToImplementation.ts
│ ├── refactorProvider.ts
│ ├── rename.ts
│ ├── transpile.ts
│ ├── outliningElementsCollector.ts
│ └── navigateTo.ts
├── extensions.ts
├── tsconfig.json
└── compiler
│ ├── performance.ts
│ └── transformers
│ ├── es7.ts
│ ├── es2016.ts
│ ├── module
│ ├── es2015.ts
│ └── es6.ts
│ ├── es5.ts
│ └── utilities.ts
├── kicktravis
├── bin
├── tsc
├── lib.es2016.d.ts
├── lib.esnext.d.ts
├── lib.es2017.d.ts
├── lib.es2017.intl.d.ts
├── lib.es2015.d.ts
├── lib.esnext.asynciterable.d.ts
├── lib.es2015.reflect.d.ts
├── lib.es2015.symbol.d.ts
├── lib.es2015.proxy.d.ts
├── lib.es2017.object.d.ts
├── lib.es2015.generator.d.ts
├── lib.es2017.string.d.ts
├── lib.es2015.collection.d.ts
├── lib.dom.iterable.d.ts
├── lib.es2016.array.include.d.ts
├── lib.es2017.sharedmemory.d.ts
├── lib.scripthost.d.ts
└── lib.scriptHost.d.ts
├── .gitmodules
├── typings
└── tsd.d.ts
├── tsd.json
├── appveyor.yml
├── .gitignore
├── extensions
├── tsconfig.json
├── preBuild.ts
├── preBuild.js
├── addExtensions.js
└── addExtensions.ts
├── Gruntfile.js
├── CONTRIBUTING.md
├── package.json
├── release.sh
├── tasks
├── ntypescript.js
└── ntypescript.ts
├── prepare.sh
├── register.js
├── register.ts
├── .travis.yml
├── tsconfig.json
└── README.md
/LICENCE:
--------------------------------------------------------------------------------
1 | MIT
2 |
--------------------------------------------------------------------------------
/tests/tse/3iwilllogargs.ts:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/grunt/fail/tsconfig.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/tests/grunt/pass/tsconfig.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/tests/tse/test.bat:
--------------------------------------------------------------------------------
1 | ntse 1start.ts
--------------------------------------------------------------------------------
/tests/grunt/pass/pass.ts:
--------------------------------------------------------------------------------
1 | var foo = 123;
--------------------------------------------------------------------------------
/tests/grunt/pass/pass.js:
--------------------------------------------------------------------------------
1 | var foo = 123;
2 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | TypeScript
2 | .gitmodules
3 | tests
--------------------------------------------------------------------------------
/tests/grunt/fail/fail.js:
--------------------------------------------------------------------------------
1 | var foo = 123;
2 | var bar = foo;
3 |
--------------------------------------------------------------------------------
/tests/grunt/fail/fail.ts:
--------------------------------------------------------------------------------
1 | var foo = 123;
2 | var bar: string = foo;
--------------------------------------------------------------------------------
/quick.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | ./prepare.sh
6 |
7 | ./release.sh
8 |
9 | npm publish
--------------------------------------------------------------------------------
/src/services/refactors/refactors.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/kicktravis:
--------------------------------------------------------------------------------
1 | 2017-06-19 [ci skip] Version: 1.201706190042.1+a2776648cd48d4937b076fb8b3e935d3d5fb27e1
2 |
--------------------------------------------------------------------------------
/bin/tsc:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var ts = require('./ntypescript.js');
3 | ts.executeCommandLine(ts.sys.args);
4 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "TypeScript"]
2 | path = TypeScript
3 | url = https://github.com/Microsoft/TypeScript.git
4 |
--------------------------------------------------------------------------------
/typings/tsd.d.ts:
--------------------------------------------------------------------------------
1 |
2 | ///
3 | ///
4 |
--------------------------------------------------------------------------------
/tests/tse/2iwillfork.ts:
--------------------------------------------------------------------------------
1 | declare var require;
2 | var cp = require('child_process');
3 | export function fork() {
4 | console.log('forking');
5 | // cp.fork("./3iwilllogargs")
6 | }
--------------------------------------------------------------------------------
/tests/tse/1start.ts:
--------------------------------------------------------------------------------
1 | console.log('started');
2 | console.log(process.cwd())
3 | console.log(require.resolve('./2iwillfork'));
4 |
5 |
6 | import iwillfork = require('./2iwillfork');
7 | iwillfork.fork();
8 |
9 |
--------------------------------------------------------------------------------
/src/services/formatting/ruleFlag.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 |
4 | /* @internal */
5 | namespace ts.formatting {
6 | export const enum RuleFlags {
7 | None,
8 | CanDeleteNewLines
9 | }
10 | }
--------------------------------------------------------------------------------
/src/services/formatting/ruleAction.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 | export const enum RuleAction {
6 | Ignore = 0x00000001,
7 | Space = 0x00000002,
8 | NewLine = 0x00000004,
9 | Delete = 0x00000008
10 | }
11 | }
--------------------------------------------------------------------------------
/src/services/formatting/formattingRequestKind.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 | export const enum FormattingRequestKind {
6 | FormatDocument,
7 | FormatSelection,
8 | FormatOnEnter,
9 | FormatOnSemicolon,
10 | FormatOnClosingCurlyBrace
11 | }
12 | }
--------------------------------------------------------------------------------
/tsd.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "v4",
3 | "repo": "borisyankov/DefinitelyTyped",
4 | "ref": "master",
5 | "path": "typings",
6 | "bundle": "typings/tsd.d.ts",
7 | "installed": {
8 | "node/node.d.ts": {
9 | "commit": "c7b1128cc9a8f5797bade826e7632b36b06a856c"
10 | },
11 | "gruntjs/gruntjs.d.ts": {
12 | "commit": "c7b1128cc9a8f5797bade826e7632b36b06a856c"
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.0.{build}
2 | os: MinGW
3 | environment:
4 | access_token:
5 | secure: keMAbmi7iJ7xgQfIIv8IWFhu2h/ghgJc43OzQ2Fr554ZPQzhohZ9/+2TA3886VCo
6 | build_script:
7 | - prepare.sh
8 | on_success:
9 | - git config --global credential.helper store
10 | - ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n"
11 | - release.sh
12 |
--------------------------------------------------------------------------------
/src/services/formatting/references.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | ///
8 | ///
9 | ///
10 | ///
11 | ///
12 | ///
--------------------------------------------------------------------------------
/src/services/formatting/rule.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 | export class Rule {
6 | constructor(
7 | public Descriptor: RuleDescriptor,
8 | public Operation: RuleOperation,
9 | public Flag: RuleFlags = RuleFlags.None) {
10 | }
11 |
12 | public toString() {
13 | return "[desc=" + this.Descriptor + "," +
14 | "operation=" + this.Operation + "," +
15 | "flag=" + this.Flag + "]";
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # node-waf configuration
20 | .lock-wscript
21 |
22 | # Compiled binary addons (http://nodejs.org/api/addons.html)
23 | build/Release
24 |
25 | # Dependency directory
26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27 | node_modules
28 |
--------------------------------------------------------------------------------
/extensions/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.5.0-beta",
3 | "compilerOptions": {
4 | "target": "es5",
5 | "module": "commonjs",
6 | "isolatedModules": false,
7 | "jsx": "react",
8 | "experimentalDecorators": true,
9 | "emitDecoratorMetadata": true,
10 | "declaration": false,
11 | "noImplicitAny": false,
12 | "removeComments": true,
13 | "noLib": false,
14 | "preserveConstEnums": true,
15 | "suppressImplicitAnyIndexErrors": true
16 | },
17 | "filesGlob": [
18 | "./**/*.ts",
19 | "./**/*.tsx"
20 | ],
21 | "files": [
22 | "./addExtensions.ts",
23 | "./preBuild.ts"
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | grunt.initConfig({
4 | ntypescript: {
5 | options: {
6 | project: '.'
7 | },
8 | default: {},
9 | pass: {
10 | options: {
11 | project: './tests/grunt/pass'
12 | }
13 | },
14 | fail: {
15 | options: {
16 | project: './tests/grunt/fail'
17 | }
18 | },
19 | },
20 | });
21 |
22 | grunt.loadTasks('tasks');
23 | // They would do:
24 | // grunt.loadNpmTasks('ntypescript');
25 |
26 | grunt.registerTask('default', ['ntypescript:default']);
27 | };
--------------------------------------------------------------------------------
/src/services/codefixes/fixes.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | ///
8 | ///
9 | ///
10 | ///
11 | ///
12 | ///
13 |
--------------------------------------------------------------------------------
/src/services/formatting/ruleOperation.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 | export class RuleOperation {
6 | constructor(public Context: RuleOperationContext, public Action: RuleAction) {}
7 |
8 | public toString(): string {
9 | return "[context=" + this.Context + "," +
10 | "action=" + this.Action + "]";
11 | }
12 |
13 | static create1(action: RuleAction) {
14 | return RuleOperation.create2(RuleOperationContext.Any, action);
15 | }
16 |
17 | static create2(context: RuleOperationContext, action: RuleAction) {
18 | return new RuleOperation(context, action);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Release
2 |
3 | ## Quickly
4 |
5 | Quick workflow (runs `prepare` and `release`):
6 |
7 | ```sh
8 | quick.sh
9 | ```
10 |
11 | ## Manually
12 |
13 | ```sh
14 | prepare.sh
15 | ```
16 |
17 | Manual verification here ... then:
18 |
19 | ```sh
20 | release.sh
21 | npm publish
22 | ```
23 |
24 | ## globals
25 |
26 | You can try the globals using:
27 |
28 | ```
29 | npm link
30 | ```
31 |
32 | # Inspiration
33 | https://github.com/Arnavion/typescript-github
34 |
35 | # Travis
36 | * NPM deploy setup by simply running `travis setup npm` (you get `travis` from `gem install travis`). Then setup the API key using https://github.com/npm/npm/issues/8970#issuecomment-122854271
37 | * Cron job setup using https://nightli.es/ (we also tried http://traviscron.pythonanywhere.com/ but it didn't work).
38 |
--------------------------------------------------------------------------------
/tests/tse/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.5.0-beta",
3 | "compilerOptions": {
4 | "target": "es5",
5 | "module": "commonjs",
6 | "isolatedModules": true,
7 | "jsx": "react",
8 | "experimentalDecorators": true,
9 | "emitDecoratorMetadata": true,
10 | "declaration": false,
11 | "noImplicitAny": false,
12 | "removeComments": true,
13 | "noLib": false,
14 | "preserveConstEnums": true,
15 | "suppressImplicitAnyIndexErrors": true
16 | },
17 | "filesGlob": [
18 | "./**/*.ts",
19 | "./**/*.tsx",
20 | "!./node_modules/**/*"
21 | ],
22 | "files": [
23 | "./1start.ts",
24 | "./2iwillfork.ts",
25 | "./3iwilllogargs.ts"
26 | ],
27 | "compileOnSave": false
28 | }
29 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ntypescript",
3 | "version": "1.201706190042.1+a2776648cd48d4937b076fb8b3e935d3d5fb27e1",
4 | "description": "A nicer version of microsoft/typescript packaged and released for API developers",
5 | "main": "./bin/ntypescript.js",
6 | "bin": {
7 | "ntsc": "./bin/tsc"
8 | },
9 | "typescript": {
10 | "definition": "./bin/ntypescript.d.ts"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/basarat/ntypescript.git"
15 | },
16 | "keywords": [
17 | "typescript",
18 | "gruntplugin"
19 | ],
20 | "author": "basaratali@gmail.com",
21 | "license": "MIT",
22 | "bugs": {
23 | "url": "https://github.com/basarat/ntypescript/issues"
24 | },
25 | "homepage": "https://github.com/basarat/ntypescript#readme",
26 | "devDependencies": {
27 | "grunt": "^0.4.5"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | # Get the git commit hash
5 | typeScriptDirectory='./TypeScript'
6 | cd $typeScriptDirectory
7 | commitHash=`git rev-parse HEAD`
8 | cd ..
9 |
10 | # Version of this script
11 | toolsVersion="1"
12 |
13 | commitVersion="1.$(date +%Y%m%d%H%M).$toolsVersion+$commitHash"
14 | commitName="$(date +%Y-%m-%d) [ci skip] Version: $commitVersion"
15 |
16 | # Kick travis
17 | echo $commitName > kicktravis
18 |
19 | # Update package.json
20 | < package.json > package.json.new sed -E "s/(\s+\"version\": \")[^\"]+(\",)/\1$commitVersion\2/"
21 | mv package.json.new package.json
22 | echo "Adding to git"
23 | git add -A
24 | git checkout master
25 | git status
26 |
27 | # Commit,tag,push,publish
28 | echo "Committing"
29 | git commit -m "$commitName"
30 | git merge HEAD@{1}
31 | echo "Pushing commit"
32 | git push
33 |
34 | echo "Tagging"
35 | git tag $commitVersion
36 | echo "Pushing tags"
37 | git push --tags
38 |
--------------------------------------------------------------------------------
/src/services/codefixes/fixForgottenThisPropertyAccess.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.codefix {
3 | registerCodeFix({
4 | errorCodes: [Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code],
5 | getCodeActions: (context: CodeFixContext) => {
6 | const sourceFile = context.sourceFile;
7 | const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
8 | if (token.kind !== SyntaxKind.Identifier) {
9 | return undefined;
10 | }
11 | const changeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
12 | changeTracker.replaceNode(sourceFile, token, createPropertyAccess(createThis(), token));
13 |
14 | return [{
15 | description: getLocaleSpecificMessage(Diagnostics.Add_this_to_unresolved_variable),
16 | changes: changeTracker.getChanges()
17 | }];
18 | }
19 | });
20 | }
--------------------------------------------------------------------------------
/bin/lib.es2016.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | ///
22 | ///
--------------------------------------------------------------------------------
/bin/lib.esnext.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | ///
22 | ///
23 |
--------------------------------------------------------------------------------
/extensions/preBuild.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Make modifications to typescript source pre build
3 | */
4 |
5 | // Utilities
6 | declare var require, __dirname;
7 | var fs = require('fs');
8 | var EOL: string = require('os').EOL;
9 | export function readFile(filePath: string): string {
10 | return fs.readFileSync(__dirname + '/' + filePath, 'utf8');
11 | }
12 | export function writeFile(filePath: string, content: string) {
13 | fs.writeFileSync(__dirname + '/' + filePath, content);
14 | }
15 |
16 |
17 | var lineFixes = [{
18 | fileName: '../src/compiler/program.ts',
19 | orig: `export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule {`,
20 | new: `export var resolveModuleName = (moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule => {`
21 | }];
22 |
23 | for (let fix of lineFixes) {
24 | writeFile(fix.fileName, readFile(fix.fileName).replace(fix.orig, fix.new));
25 | }
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/services/formatting/ruleOperationContext.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 |
6 | export class RuleOperationContext {
7 | private customContextChecks: { (context: FormattingContext): boolean; }[];
8 |
9 | constructor(...funcs: { (context: FormattingContext): boolean; }[]) {
10 | this.customContextChecks = funcs;
11 | }
12 |
13 | static Any: RuleOperationContext = new RuleOperationContext();
14 |
15 | public IsAny(): boolean {
16 | return this === RuleOperationContext.Any;
17 | }
18 |
19 | public InContext(context: FormattingContext): boolean {
20 | if (this.IsAny()) {
21 | return true;
22 | }
23 |
24 | for (const check of this.customContextChecks) {
25 | if (!check(context)) {
26 | return false;
27 | }
28 | }
29 | return true;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/tasks/ntypescript.js:
--------------------------------------------------------------------------------
1 | /*
2 | * ntypescript
3 | * https://github.com/basarat/ntypescript
4 | *
5 | * Copyright (c) 2015 Basarat Syed
6 | * Licensed under the MIT license.
7 | */
8 | var path = require("path");
9 | function gruntPlugin(grunt) {
10 | grunt.registerMultiTask('ntypescript', 'TypeScript grunt plugin', function () {
11 | var options = {
12 | project: '.',
13 | };
14 | options = this.options(options);
15 | if (!options.project) {
16 | console.error('tsconfig must be specified using options');
17 | return false;
18 | }
19 | var project = path.resolve(options.project);
20 | var args = [__dirname + '/../bin/tsc', '-p', project];
21 | var done = this.async();
22 | grunt.util.spawn({
23 | cmd: process.execPath,
24 | args: args
25 | }, function (error, result, code) {
26 | console.log(result.stdout || result.stderr);
27 | done(!code);
28 | });
29 | });
30 | }
31 | ;
32 | module.exports = gruntPlugin;
33 |
--------------------------------------------------------------------------------
/src/services/transform.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | namespace ts {
4 | /**
5 | * Transform one or more nodes using the supplied transformers.
6 | * @param source A single `Node` or an array of `Node` objects.
7 | * @param transformers An array of `TransformerFactory` callbacks used to process the transformation.
8 | * @param compilerOptions Optional compiler options.
9 | */
10 | export function transform(source: T | T[], transformers: TransformerFactory[], compilerOptions?: CompilerOptions) {
11 | const diagnostics: Diagnostic[] = [];
12 | compilerOptions = fixupCompilerOptions(compilerOptions, diagnostics);
13 | const nodes = isArray(source) ? source : [source];
14 | const result = transformNodes(/*resolver*/ undefined, /*emitHost*/ undefined, compilerOptions, nodes, transformers, /*allowDtsFiles*/ true);
15 | result.diagnostics = concatenate(result.diagnostics, diagnostics);
16 | return result;
17 | }
18 | }
--------------------------------------------------------------------------------
/extensions/preBuild.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var fs = require('fs');
4 | var EOL = require('os').EOL;
5 | function readFile(filePath) {
6 | return fs.readFileSync(__dirname + '/' + filePath, 'utf8');
7 | }
8 | exports.readFile = readFile;
9 | function writeFile(filePath, content) {
10 | fs.writeFileSync(__dirname + '/' + filePath, content);
11 | }
12 | exports.writeFile = writeFile;
13 | var lineFixes = [{
14 | fileName: '../src/compiler/program.ts',
15 | orig: "export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule {",
16 | new: "export var resolveModuleName = (moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule => {"
17 | }];
18 | for (var _i = 0, lineFixes_1 = lineFixes; _i < lineFixes_1.length; _i++) {
19 | var fix = lineFixes_1[_i];
20 | writeFile(fix.fileName, readFile(fix.fileName).replace(fix.orig, fix.new));
21 | }
22 |
--------------------------------------------------------------------------------
/extensions/addExtensions.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | var fs = require('fs');
4 | var EOL = require('os').EOL;
5 | function readFile(filePath) {
6 | return fs.readFileSync(__dirname + '/' + filePath, 'utf8');
7 | }
8 | exports.readFile = readFile;
9 | function writeFile(filePath, content) {
10 | fs.writeFileSync(__dirname + '/' + filePath, content);
11 | }
12 | exports.writeFile = writeFile;
13 | var dtsOriginal = readFile('../bin/typescript.d.ts');
14 | var jsOriginal = readFile('../bin/typescript.js');
15 | var finalDtsLocation = '../bin/ntypescript.d.ts';
16 | var finalJsLocation = '../bin/ntypescript.js';
17 | var finalDtsContent = dtsOriginal;
18 | var finalJsContent = jsOriginal;
19 | finalDtsContent = finalDtsContent + EOL + "\ndeclare module \"ntypescript\" {\n export = ts;\n}\n";
20 | finalDtsContent = finalDtsContent.replace(/const enum /g, 'enum ');
21 | finalJsContent = finalJsContent.replace(/ts.executeCommandLine\(ts\.sys\.args\);/g, '');
22 | writeFile(finalDtsLocation, finalDtsContent);
23 | writeFile(finalJsLocation, finalJsContent);
24 |
--------------------------------------------------------------------------------
/bin/lib.es2017.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | ///
22 | ///
23 | ///
24 | ///
25 | ///
26 |
--------------------------------------------------------------------------------
/src/services/codefixes/fixConstructorForDerivedNeedSuperCall.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.codefix {
3 | registerCodeFix({
4 | errorCodes: [Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call.code],
5 | getCodeActions: (context: CodeFixContext) => {
6 | const sourceFile = context.sourceFile;
7 | const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
8 |
9 | if (token.kind !== SyntaxKind.ConstructorKeyword) {
10 | return undefined;
11 | }
12 |
13 | const changeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
14 | const superCall = createStatement(createCall(createSuper(), /*typeArguments*/ undefined, /*argumentsArray*/ emptyArray));
15 | changeTracker.insertNodeAfter(sourceFile, getOpenBrace(token.parent, sourceFile), superCall, { suffix: context.newLineCharacter });
16 |
17 | return [{
18 | description: getLocaleSpecificMessage(Diagnostics.Add_missing_super_call),
19 | changes: changeTracker.getChanges()
20 | }];
21 | }
22 | });
23 | }
--------------------------------------------------------------------------------
/tasks/ntypescript.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * ntypescript
3 | * https://github.com/basarat/ntypescript
4 | *
5 | * Copyright (c) 2015 Basarat Syed
6 | * Licensed under the MIT license.
7 | */
8 |
9 | import * as path from "path";
10 |
11 | function gruntPlugin(grunt) {
12 | grunt.registerMultiTask('ntypescript', 'TypeScript grunt plugin', function() {
13 | // Merge task-specific and/or target-specific options with these defaults.
14 | var options = {
15 | project: '.',
16 | };
17 | options = this.options(options);
18 |
19 | if (!options.project) {
20 | console.error('tsconfig must be specified using options');
21 | return false;
22 | }
23 |
24 | const project: string = path.resolve(options.project);
25 | const args = [__dirname + '/../bin/tsc', '-p', project];
26 | // console.log(args); // Debug
27 |
28 | var done = this.async();
29 | grunt.util.spawn({
30 | cmd: process.execPath,
31 | args: args
32 | }, (error, result, code: number) => {
33 | console.log(result.stdout || result.stderr);
34 | done(!code);
35 | });
36 | });
37 | };
38 |
39 | export = gruntPlugin;
--------------------------------------------------------------------------------
/prepare.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | git submodule update --recursive --init
5 |
6 | # Official Microsoft/TypeScript clone
7 | cd ./TypeScript
8 |
9 | git clean -xfd
10 | git fetch origin
11 | git reset --hard origin/master
12 |
13 | # Fix jakefile to expose the internal APIs to service
14 | < Jakefile.js > Jakefile.new.js sed -E "s/\*stripInternal\*\/ true/\*stripInternal\*\/ false/"
15 | mv Jakefile.new.js Jakefile.js
16 |
17 | # Install jake and everything else
18 | npm install
19 |
20 | # Build once to get a new LKG
21 | ./node_modules/.bin/jake release tsc --trace
22 | cp ./built/local/* ./bin/
23 |
24 | # Copy the source TypeScript compiler and services, but not the tsconfig.json files
25 | cp -r ./src/compiler/* ../src/compiler
26 | cp -r ./src/services/* ../src/services
27 | rm ../src/services/tsconfig.json ../src/compiler/tsconfig.json
28 |
29 | # Do pre build modifications
30 | node ../extensions/preBuild.js
31 |
32 | # Now build using the LKG
33 | ./bin/tsc -p ../src
34 | ./bin/tsc -p ../extensions
35 |
36 | # Also copy the lib.* stuff from LKG
37 | cp ./bin/lib* ../bin
38 |
39 | # add custom extension
40 | node ../extensions/addExtensions.js
41 |
42 | # Reset sub typescript
43 | git reset --hard origin/master
44 | cd ..
45 |
--------------------------------------------------------------------------------
/src/services/formatting/ruleDescriptor.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 | export class RuleDescriptor {
6 | constructor(public LeftTokenRange: Shared.TokenRange, public RightTokenRange: Shared.TokenRange) {
7 | }
8 |
9 | public toString(): string {
10 | return "[leftRange=" + this.LeftTokenRange + "," +
11 | "rightRange=" + this.RightTokenRange + "]";
12 | }
13 |
14 | static create1(left: SyntaxKind, right: SyntaxKind): RuleDescriptor {
15 | return RuleDescriptor.create4(Shared.TokenRange.FromToken(left), Shared.TokenRange.FromToken(right));
16 | }
17 |
18 | static create2(left: Shared.TokenRange, right: SyntaxKind): RuleDescriptor {
19 | return RuleDescriptor.create4(left, Shared.TokenRange.FromToken(right));
20 | }
21 |
22 | static create3(left: SyntaxKind, right: Shared.TokenRange): RuleDescriptor {
23 | return RuleDescriptor.create4(Shared.TokenRange.FromToken(left), right);
24 | }
25 |
26 | static create4(left: Shared.TokenRange, right: Shared.TokenRange): RuleDescriptor {
27 | return new RuleDescriptor(left, right);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/bin/lib.es2017.intl.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | type DateTimeFormatPartTypes = "day" | "dayPeriod" | "era" | "hour" | "literal" | "minute" | "month" | "second" | "timeZoneName" | "weekday" | "year";
22 |
23 | interface DateTimeFormatPart {
24 | type: DateTimeFormatPartTypes;
25 | value: string;
26 | }
27 |
28 | interface DateTimeFormat {
29 | formatToParts(date?: Date | number): DateTimeFormatPart[];
30 | }
31 |
--------------------------------------------------------------------------------
/src/extensions.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Sample: add a new utility function
3 | */
4 | module ts {
5 | export function syntaxKindToName(kind: ts.SyntaxKind): string {
6 | return (ts).SyntaxKind[kind];
7 | }
8 |
9 | /**
10 | * Pulled straight out of `tsc.ts`. Ask to make it exported
11 | */
12 | export function reportDiagnostic(diagnostic: Diagnostic) {
13 | let output = "";
14 |
15 | if (diagnostic.file) {
16 | let loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
17 |
18 | output += `${ diagnostic.file.fileName }(${ loc.line + 1 },${ loc.character + 1 }): `;
19 | }
20 |
21 | let category = DiagnosticCategory[diagnostic.category].toLowerCase();
22 | output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`;
23 |
24 | sys.write(output);
25 | }
26 | }
27 |
28 | /**
29 | * Make ts a global variable (this means we have a consistent typescript definition file)
30 | */
31 | declare module NodeJS {
32 | export interface Global {
33 | }
34 | }
35 | declare var global: NodeJS.Global;
36 | if (typeof global !== "undefined") {
37 | (global as any).ts = ts;
38 | }
39 | if (typeof window !== "undefined") {
40 | (window as any).ts = ts;
41 | }
42 |
--------------------------------------------------------------------------------
/src/services/formatting/rulesProvider.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | /* @internal */
4 | namespace ts.formatting {
5 | export class RulesProvider {
6 | private globalRules: Rules;
7 | private options: ts.FormatCodeSettings;
8 | private rulesMap: RulesMap;
9 |
10 | constructor() {
11 | this.globalRules = new Rules();
12 | const activeRules = this.globalRules.HighPriorityCommonRules.slice(0).concat(this.globalRules.UserConfigurableRules).concat(this.globalRules.LowPriorityCommonRules);
13 | this.rulesMap = RulesMap.create(activeRules);
14 | }
15 |
16 | public getRuleName(rule: Rule): string {
17 | return this.globalRules.getRuleName(rule);
18 | }
19 |
20 | public getRuleByName(name: string): Rule {
21 | return this.globalRules[name];
22 | }
23 |
24 | public getRulesMap() {
25 | return this.rulesMap;
26 | }
27 |
28 | public getFormatOptions(): Readonly {
29 | return this.options;
30 | }
31 |
32 | public ensureUpToDate(options: ts.FormatCodeSettings) {
33 | if (!this.options || !ts.compareDataObjects(this.options, options)) {
34 | this.options = ts.clone(options);
35 | }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/bin/lib.es2015.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | ///
22 | ///
23 | ///
24 | ///
25 | ///
26 | ///
27 | ///
28 | ///
29 | ///
30 | ///
--------------------------------------------------------------------------------
/register.js:
--------------------------------------------------------------------------------
1 | ///
2 | var t = require('./bin/typescript.js');
3 | var fileExtension = ['.ts', '.tsx'];
4 | exports.isTypeScript = function (file) {
5 | var r = new RegExp("\\.(" + fileExtension.join("|") + ")$");
6 | return r.test(file);
7 | };
8 | var fs = require('fs');
9 | function loadFile(module, filename) {
10 | var configFile = t.findConfigFile(filename);
11 | var compilerOpts = {
12 | module: 1,
13 | target: 1
14 | };
15 | if (configFile) {
16 | var configFileContents = t.readConfigFile(configFile);
17 | var opts = configFileContents.config;
18 | opts.files = [];
19 | compilerOpts = t.parseConfigFile(opts, null, process.cwd()).options;
20 | }
21 | var js = t.transpile(fs.readFileSync(filename, 'utf8'), compilerOpts);
22 | module._compile(js, filename);
23 | }
24 | exports.loadFile = loadFile;
25 | if (require.extensions) {
26 | for (var _i = 0; _i < fileExtension.length; _i++) {
27 | var ext = fileExtension[_i];
28 | require.extensions[ext] = loadFile;
29 | }
30 | }
31 | var child_process = require('child_process');
32 | if (child_process) {
33 | var fork = child_process.fork;
34 | var binary = require.resolve('./bin/tse');
35 | child_process.fork = function (path, args, options) {
36 | if (exports.isTypeScript(path)) {
37 | if (!Array.isArray(args)) {
38 | options = args || {};
39 | args = [];
40 | }
41 | args = [path].concat(args);
42 | path = binary;
43 | }
44 | fork(path, args, options);
45 | };
46 | }
47 |
--------------------------------------------------------------------------------
/extensions/addExtensions.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This script is responsible for making required modifications to our version of TypeScript post build
3 | */
4 |
5 | // Utilities
6 | declare var require, __dirname;
7 | var fs = require('fs');
8 | var EOL: string = require('os').EOL;
9 | export function readFile(filePath: string): string {
10 | return fs.readFileSync(__dirname + '/' + filePath, 'utf8');
11 | }
12 | export function writeFile(filePath: string, content: string) {
13 | fs.writeFileSync(__dirname + '/' + filePath, content);
14 | }
15 |
16 | // Read original files
17 | var dtsOriginal = readFile('../bin/typescript.d.ts');
18 | var jsOriginal = readFile('../bin/typescript.js');
19 |
20 | // Setup final output destinations
21 | var finalDtsLocation = '../bin/ntypescript.d.ts';
22 | var finalJsLocation = '../bin/ntypescript.js';
23 |
24 | // Setup final output
25 | var finalDtsContent = dtsOriginal;
26 | var finalJsContent = jsOriginal;
27 |
28 | /**
29 | * Transform as needed
30 | */
31 |
32 | // Add global import
33 | finalDtsContent = finalDtsContent + EOL + `
34 | declare module "ntypescript" {
35 | export = ts;
36 | }
37 | `;
38 | // I think the `const enum` causes more pain than its worth for dev tools (everything needs to be rebuilt). So change to enum to prevent inlining
39 | finalDtsContent = finalDtsContent.replace(/const enum /g, 'enum ');
40 |
41 | // No need for `ts.executeCommandLine(ts.sys.args);` in ntypescript. Its called from `tsc` manually
42 | finalJsContent = finalJsContent.replace(/ts.executeCommandLine\(ts\.sys\.args\);/g, '');
43 |
44 | /**
45 | * Write out outputs
46 | */
47 | writeFile(finalDtsLocation, finalDtsContent);
48 | writeFile(finalJsLocation, finalJsContent);
49 |
--------------------------------------------------------------------------------
/bin/lib.esnext.asynciterable.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | ///
22 | ///
23 |
24 | interface SymbolConstructor {
25 | /**
26 | * A method that returns the default async iterator for an object. Called by the semantics of
27 | * the for-await-of statement.
28 | */
29 | readonly asyncIterator: symbol;
30 | }
31 |
32 | interface AsyncIterator {
33 | next(value?: any): Promise>;
34 | return?(value?: any): Promise>;
35 | throw?(e?: any): Promise>;
36 | }
37 |
38 | interface AsyncIterable {
39 | [Symbol.asyncIterator](): AsyncIterator;
40 | }
41 |
42 | interface AsyncIterableIterator extends AsyncIterator {
43 | [Symbol.asyncIterator](): AsyncIterableIterator;
44 | }
--------------------------------------------------------------------------------
/src/services/codeFixProvider.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts {
3 | export interface CodeFix {
4 | errorCodes: number[];
5 | getCodeActions(context: CodeFixContext): CodeAction[] | undefined;
6 | }
7 |
8 | export interface CodeFixContext {
9 | errorCode: number;
10 | sourceFile: SourceFile;
11 | span: TextSpan;
12 | program: Program;
13 | newLineCharacter: string;
14 | host: LanguageServiceHost;
15 | cancellationToken: CancellationToken;
16 | rulesProvider: formatting.RulesProvider;
17 | }
18 |
19 | export namespace codefix {
20 | const codeFixes: CodeFix[][] = [];
21 |
22 | export function registerCodeFix(codeFix: CodeFix) {
23 | forEach(codeFix.errorCodes, error => {
24 | let fixes = codeFixes[error];
25 | if (!fixes) {
26 | fixes = [];
27 | codeFixes[error] = fixes;
28 | }
29 | fixes.push(codeFix);
30 | });
31 | }
32 |
33 | export function getSupportedErrorCodes() {
34 | return Object.keys(codeFixes);
35 | }
36 |
37 | export function getFixes(context: CodeFixContext): CodeAction[] {
38 | const fixes = codeFixes[context.errorCode];
39 | let allActions: CodeAction[] = [];
40 |
41 | forEach(fixes, f => {
42 | const actions = f.getCodeActions(context);
43 | if (actions && actions.length > 0) {
44 | allActions = allActions.concat(actions);
45 | }
46 | });
47 |
48 | return allActions;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/services/goToImplementation.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.GoToImplementation {
3 | export function getImplementationAtPosition(typeChecker: TypeChecker, cancellationToken: CancellationToken, sourceFiles: SourceFile[], node: Node): ImplementationLocation[] {
4 | // If invoked directly on a shorthand property assignment, then return
5 | // the declaration of the symbol being assigned (not the symbol being assigned to).
6 | if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
7 | const result: ReferenceEntry[] = [];
8 | FindAllReferences.getReferenceEntriesForShorthandPropertyAssignment(node, typeChecker, result);
9 | return result.length > 0 ? result : undefined;
10 | }
11 | else if (node.kind === SyntaxKind.SuperKeyword || isSuperProperty(node.parent)) {
12 | // References to and accesses on the super keyword only have one possible implementation, so no
13 | // need to "Find all References"
14 | const symbol = typeChecker.getSymbolAtLocation(node);
15 | return symbol.valueDeclaration && [FindAllReferences.getReferenceEntryFromNode(symbol.valueDeclaration)];
16 | }
17 | else {
18 | // Perform "Find all References" and retrieve only those that are implementations
19 | const referencedSymbols = FindAllReferences.getReferencedSymbolsForNode(typeChecker, cancellationToken,
20 | node, sourceFiles, /*findInStrings*/false, /*findInComments*/false, /*implementations*/true);
21 | const result = flatMap(referencedSymbols, symbol =>
22 | map(symbol.references, ({ textSpan, fileName }) => ({ textSpan, fileName })));
23 |
24 | return result && result.length > 0 ? result : undefined;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/register.ts:
--------------------------------------------------------------------------------
1 | ///
2 | var t: typeof ts = require('./bin/typescript.js');
3 |
4 | /** Determine if a filename represents a TypeScript file. */
5 | var fileExtension = ['.ts', '.tsx'];
6 | export var isTypeScript = (file) => {
7 | let r = new RegExp("\\.("+fileExtension.join("|") +")$");
8 | return r.test(file);
9 | }
10 |
11 | /** Load and runt TypeScript for Node */
12 | import fs = require('fs');
13 | export function loadFile(module, filename) {
14 | var configFile = t.findConfigFile(filename);
15 | var compilerOpts = {
16 | module: t.ModuleKind.CommonJS,
17 | target: t.ScriptTarget.ES5
18 | };
19 | if (configFile) {
20 | var configFileContents = t.readConfigFile(configFile);
21 | var opts = configFileContents.config;
22 | opts.files = [];
23 | compilerOpts = t.parseConfigFile(opts, null, process.cwd()).options;
24 | }
25 | var js = t.transpile(fs.readFileSync(filename,'utf8'), compilerOpts);
26 | module._compile(js, filename);
27 | }
28 |
29 | /** If the installed version of Node supports require.extensions, register TypeScript as an extension. */
30 | if (require.extensions) {
31 | for (var ext of fileExtension) {
32 | require.extensions[ext] = loadFile;
33 | }
34 | }
35 |
36 | /** If we’re on Node, patch child_process.fork so that TypeScript is able to fork both TypeScript files, and JavaScript files, directly. */
37 | import child_process = require('child_process');
38 | if (child_process) {
39 | var {fork} = child_process;
40 | var binary = require.resolve('./bin/tse');
41 | child_process.fork = function(path, args?, options?) {
42 | if (isTypeScript(path)) {
43 | if (!Array.isArray(args)) {
44 | options = args || {}
45 | args = []
46 | }
47 | args = [path].concat(args)
48 | path = binary
49 | }
50 | fork(path, args, options)
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/bin/lib.es2015.reflect.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | declare namespace Reflect {
22 | function apply(target: Function, thisArgument: any, argumentsList: ArrayLike): any;
23 | function construct(target: Function, argumentsList: ArrayLike, newTarget?: any): any;
24 | function defineProperty(target: object, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean;
25 | function deleteProperty(target: object, propertyKey: PropertyKey): boolean;
26 | function get(target: object, propertyKey: PropertyKey, receiver?: any): any;
27 | function getOwnPropertyDescriptor(target: object, propertyKey: PropertyKey): PropertyDescriptor;
28 | function getPrototypeOf(target: object): object;
29 | function has(target: object, propertyKey: PropertyKey): boolean;
30 | function isExtensible(target: object): boolean;
31 | function ownKeys(target: object): Array;
32 | function preventExtensions(target: object): boolean;
33 | function set(target: object, propertyKey: PropertyKey, value: any, receiver?: any): boolean;
34 | function setPrototypeOf(target: object, proto: any): boolean;
35 | }
36 |
--------------------------------------------------------------------------------
/src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.codefix {
3 | registerCodeFix({
4 | errorCodes: [Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements.code],
5 | getCodeActions: (context: CodeFixContext) => {
6 | const sourceFile = context.sourceFile;
7 | const start = context.span.start;
8 | const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
9 | const classDeclNode = getContainingClass(token);
10 | if (!(token.kind === SyntaxKind.Identifier && isClassLike(classDeclNode))) {
11 | return undefined;
12 | }
13 |
14 | const heritageClauses = classDeclNode.heritageClauses;
15 | if (!(heritageClauses && heritageClauses.length > 0)) {
16 | return undefined;
17 | }
18 |
19 | const extendsToken = heritageClauses[0].getFirstToken();
20 | if (!(extendsToken && extendsToken.kind === SyntaxKind.ExtendsKeyword)) {
21 | return undefined;
22 | }
23 |
24 | const changeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
25 | changeTracker.replaceNode(sourceFile, extendsToken, createToken(SyntaxKind.ImplementsKeyword));
26 |
27 | // We replace existing keywords with commas.
28 | for (let i = 1; i < heritageClauses.length; i++) {
29 | const keywordToken = heritageClauses[i].getFirstToken();
30 | if (keywordToken) {
31 | changeTracker.replaceNode(sourceFile, keywordToken, createToken(SyntaxKind.CommaToken));
32 | }
33 | }
34 |
35 | const result = [{
36 | description: getLocaleSpecificMessage(Diagnostics.Change_extends_to_implements),
37 | changes: changeTracker.getChanges()
38 | }];
39 |
40 | return result;
41 | }
42 | });
43 | }
44 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 5
4 | env:
5 | global:
6 | - secure: WXkeUKwWKTv2uUCyIiDdQ0e5gQCoX9gGj6wiNh9G7IATqcecxTw6cpQGj3J8YWDIjbtNXfAkJwohhGtXYr7VnkXRA1s0POYM+8cvM5I+ZDtZkXM9EvCwMYxf9XZ8qQ/4fegeSoZqfx1qgh+Sfh6Wp93I4W+AfB8VONLIGgXr172QGwYmkynPpC//mYA6sUZoQo4Y796PtBblc+7oM0a5A5chQ5r1CVqPqRZ/i9aNrH2UTdYjCMNE395LqwHSJGk5eunT5ebA4OcClme1wL78MJtGS1ZZIOEHSBv7mBrOcp29kYknc/m1PaOYBMdppmRBLr6Q5oUg8QzaILW2TypsWkosWpSlbemW1lsutqlFRkmtsjfX3ZVOoeIx/7J9v+pDA2gb7VMtNzwlkRpcLfHBmfuXuiPNXwLS1Ogl2D8JUD+rjwB3FI6pE2zZqNL7zMe7yhCQ/1wqGdlNqB1Ifb9T2RRkDCEUr+dw3sGn6Ecgk4XThUwY3vVzABj0C906Wc7UpsVvf1qjLCRg48lYG8kmhLqEylL+IUs3XXMSv69/YLxnDvRdF/d1FZHWKcoTeWYmXr3k1q0ePYEDXpX6/8MXWix1Qql4AAOjIxOgRufBPlDWe6QS2b97K4OPo+m3cf/RaLPz+jUOpf59l6CNnceBYLKs00Taf0KSgs+YVADAV6M=
7 | before_script:
8 | - git config --global user.email "basaratali@gmail.com"
9 | - git config --global user.name "Travis-CI"
10 | - git remote set-url origin https://github.com/TypeStrong/ntypescript.git
11 | script:
12 | - bash prepare.sh
13 | after_success:
14 | - git config credential.helper "store --file=.git/credentials"
15 | - echo "https://${GH_TOKEN}:@github.com" > .git/credentials
16 | - git config --global push.default matching
17 | - bash release.sh
18 | branches:
19 | only:
20 | - master
21 | deploy:
22 | provider: npm
23 | email: basaratali@gmail.com
24 | api_key:
25 | secure: s/KSMaTnT6JdVOmaw5n3KnA5piUjxopXjOEH/k2uTph2zY7XVvGw83UX797IUDNTRKAX1OrgfaB+VQ+bT1Tf7KAqOgy1MtvS/lFJMMmRO5U1HI8Dj5NXWQ87GFHO1/iDZgVxRju/kkjxG/WkBfkJCex0B2smqC0HFWZKBOWlBLgjJGHs+gZV02CzWQc72kZ9PRTxbeh5Lid2D7NXAY1BfFKHyvAlibd+3sZTdjfeVQzyGg94I6pNQOpr1O0MzKv7ttZ+7iEN2cLoH9t/2927LdR1lIlyl7ArE/UY5ob4W9PpwXYXjb4O1j7vvo/S33bgXzKy1cwL1udoe5B9MvUoU8Qg64ffqyD+RRhj2ZgnnXhYIovDwOEYFbRSMgaYgoI54ThpyQXZbvwxuqWxMh5rSeUGzi5Ah36Z6zqfSYo5J7XC+mXUiqBfIXNjOpbw43rASLiM25/rMvXVDlEeDh1rgpIKDu2DVuX0Zyw4apNu+7cjlFfZ0iQwVAN5xzzJ2DOgPNosjbWe5g4RR5t2bBq9CxDYxQPNB7x1GhUk82qlij23ssoLfvNyYuLaoILuCyDly1FLHr1U6Q9VBOKvLR7qqjn0F7ZpEi8RKbNgpqNWf7ExXDOcNuoHHuHJWvKMDfj8xlkV9PeWFkCiYtm6xr1DQd/6HUkN+uh/d8SjNkgJlPM=
26 | on:
27 | repo: TypeStrong/ntypescript
28 |
--------------------------------------------------------------------------------
/bin/lib.es2015.symbol.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | interface Symbol {
22 | /** Returns a string representation of an object. */
23 | toString(): string;
24 |
25 | /** Returns the primitive value of the specified object. */
26 | valueOf(): symbol;
27 | }
28 |
29 | interface SymbolConstructor {
30 | /**
31 | * A reference to the prototype.
32 | */
33 | readonly prototype: Symbol;
34 |
35 | /**
36 | * Returns a new unique Symbol value.
37 | * @param description Description of the new Symbol object.
38 | */
39 | (description?: string | number): symbol;
40 |
41 | /**
42 | * Returns a Symbol object from the global symbol registry matching the given key if found.
43 | * Otherwise, returns a new symbol with this key.
44 | * @param key key to search for.
45 | */
46 | for(key: string): symbol;
47 |
48 | /**
49 | * Returns a key from the global symbol registry matching the given Symbol if found.
50 | * Otherwise, returns a undefined.
51 | * @param sym Symbol to find the key for.
52 | */
53 | keyFor(sym: symbol): string | undefined;
54 | }
55 |
56 | declare var Symbol: SymbolConstructor;
--------------------------------------------------------------------------------
/bin/lib.es2015.proxy.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | interface ProxyHandler {
22 | getPrototypeOf? (target: T): object | null;
23 | setPrototypeOf? (target: T, v: any): boolean;
24 | isExtensible? (target: T): boolean;
25 | preventExtensions? (target: T): boolean;
26 | getOwnPropertyDescriptor? (target: T, p: PropertyKey): PropertyDescriptor | undefined;
27 | has? (target: T, p: PropertyKey): boolean;
28 | get? (target: T, p: PropertyKey, receiver: any): any;
29 | set? (target: T, p: PropertyKey, value: any, receiver: any): boolean;
30 | deleteProperty? (target: T, p: PropertyKey): boolean;
31 | defineProperty? (target: T, p: PropertyKey, attributes: PropertyDescriptor): boolean;
32 | enumerate? (target: T): PropertyKey[];
33 | ownKeys? (target: T): PropertyKey[];
34 | apply? (target: T, thisArg: any, argArray?: any): any;
35 | construct? (target: T, argArray: any, newTarget?: any): object;
36 | }
37 |
38 | interface ProxyConstructor {
39 | revocable(target: T, handler: ProxyHandler): { proxy: T; revoke: () => void; };
40 | new (target: T, handler: ProxyHandler): T;
41 | }
42 | declare var Proxy: ProxyConstructor;
43 |
--------------------------------------------------------------------------------
/bin/lib.es2017.object.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | interface ObjectConstructor {
22 | /**
23 | * Returns an array of values of the enumerable properties of an object
24 | * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
25 | */
26 | values(o: { [s: string]: T }): T[];
27 |
28 | /**
29 | * Returns an array of values of the enumerable properties of an object
30 | * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
31 | */
32 | values(o: any): any[];
33 |
34 | /**
35 | * Returns an array of key/values of the enumerable properties of an object
36 | * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
37 | */
38 | entries(o: { [s: string]: T }): [string, T][];
39 |
40 | /**
41 | * Returns an array of key/values of the enumerable properties of an object
42 | * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
43 | */
44 | entries(o: any): [string, any][];
45 | }
46 |
--------------------------------------------------------------------------------
/src/services/codefixes/fixSpelling.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.codefix {
3 | registerCodeFix({
4 | errorCodes: [Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code,
5 | Diagnostics.Cannot_find_name_0_Did_you_mean_1.code],
6 | getCodeActions: getActionsForCorrectSpelling
7 | });
8 |
9 | function getActionsForCorrectSpelling(context: CodeFixContext): CodeAction[] | undefined {
10 | const sourceFile = context.sourceFile;
11 |
12 | // This is the identifier of the misspelled word. eg:
13 | // this.speling = 1;
14 | // ^^^^^^^
15 | const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false); // TODO: GH#15852
16 | const checker = context.program.getTypeChecker();
17 | let suggestion: string;
18 | if (node.kind === SyntaxKind.Identifier && isPropertyAccessExpression(node.parent)) {
19 | const containingType = checker.getTypeAtLocation(node.parent.expression);
20 | suggestion = checker.getSuggestionForNonexistentProperty(node as Identifier, containingType);
21 | }
22 | else {
23 | const meaning = getMeaningFromLocation(node);
24 | suggestion = checker.getSuggestionForNonexistentSymbol(node, getTextOfNode(node), convertSemanticMeaningToSymbolFlags(meaning));
25 | }
26 | if (suggestion) {
27 | return [{
28 | description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Change_spelling_to_0), [suggestion]),
29 | changes: [{
30 | fileName: sourceFile.fileName,
31 | textChanges: [{
32 | span: { start: node.getStart(), length: node.getWidth() },
33 | newText: suggestion
34 | }],
35 | }],
36 | }];
37 | }
38 | }
39 |
40 | function convertSemanticMeaningToSymbolFlags(meaning: SemanticMeaning): SymbolFlags {
41 | let flags = 0;
42 | if (meaning & SemanticMeaning.Namespace) {
43 | flags |= SymbolFlags.Namespace;
44 | }
45 | if (meaning & SemanticMeaning.Type) {
46 | flags |= SymbolFlags.Type;
47 | }
48 | if (meaning & SemanticMeaning.Value) {
49 | flags |= SymbolFlags.Value;
50 | }
51 | return flags;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.5.3",
3 | "compilerOptions": {
4 | "target": "es5",
5 | "isolatedModules": false,
6 | "jsx": "react",
7 | "experimentalDecorators": true,
8 | "emitDecoratorMetadata": true,
9 | "declaration": true,
10 | "noImplicitAny": false,
11 | "removeComments": false,
12 | "noLib": false,
13 | "preserveConstEnums": true,
14 | "suppressImplicitAnyIndexErrors": true,
15 | "out": "../bin/typescript.js"
16 | },
17 | "scripts": {
18 | "postbuild" : "node ../extensions/addExtensions.js"
19 | },
20 | "buildOnSave": true,
21 | "files": [
22 | "./compiler/parser.ts",
23 | "./compiler/binder.ts",
24 | "./compiler/checker.ts",
25 | "./compiler/commandLineParser.ts",
26 | "./compiler/core.ts",
27 | "./compiler/sys.ts",
28 | "./compiler/declarationEmitter.ts",
29 | "./compiler/diagnosticInformationMap.generated.ts",
30 | "./compiler/emitter.ts",
31 | "./compiler/program.ts",
32 | "./compiler/scanner.ts",
33 | "./compiler/tsc.ts",
34 | "./compiler/types.ts",
35 | "./compiler/utilities.ts",
36 | "./services/breakpoints.ts",
37 | "./services/formatting/formatting.ts",
38 | "./services/formatting/formattingContext.ts",
39 | "./services/formatting/formattingRequestKind.ts",
40 | "./services/formatting/formattingScanner.ts",
41 | "./services/formatting/references.ts",
42 | "./services/formatting/rule.ts",
43 | "./services/formatting/ruleAction.ts",
44 | "./services/formatting/ruleDescriptor.ts",
45 | "./services/formatting/ruleFlag.ts",
46 | "./services/formatting/ruleOperation.ts",
47 | "./services/formatting/ruleOperationContext.ts",
48 | "./services/formatting/rules.ts",
49 | "./services/formatting/rulesMap.ts",
50 | "./services/formatting/rulesProvider.ts",
51 | "./services/formatting/smartIndenter.ts",
52 | "./services/formatting/tokenRange.ts",
53 | "./services/navigateTo.ts",
54 | "./services/navigationBar.ts",
55 | "./services/outliningElementsCollector.ts",
56 | "./services/patternMatcher.ts",
57 | "./services/services.ts",
58 | "./services/shims.ts",
59 | "./services/signatureHelp.ts",
60 | "./services/utilities.ts",
61 | "./extensions.ts"
62 | ]
63 | }
64 |
--------------------------------------------------------------------------------
/bin/lib.es2015.generator.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | interface Generator extends Iterator { }
22 |
23 | interface GeneratorFunction {
24 | /**
25 | * Creates a new Generator object.
26 | * @param args A list of arguments the function accepts.
27 | */
28 | new (...args: any[]): Generator;
29 | /**
30 | * Creates a new Generator object.
31 | * @param args A list of arguments the function accepts.
32 | */
33 | (...args: any[]): Generator;
34 | /**
35 | * The length of the arguments.
36 | */
37 | readonly length: number;
38 | /**
39 | * Returns the name of the function.
40 | */
41 | readonly name: string;
42 | /**
43 | * A reference to the prototype.
44 | */
45 | readonly prototype: Generator;
46 | }
47 |
48 | interface GeneratorFunctionConstructor {
49 | /**
50 | * Creates a new Generator function.
51 | * @param args A list of arguments the function accepts.
52 | */
53 | new (...args: string[]): GeneratorFunction;
54 | /**
55 | * Creates a new Generator function.
56 | * @param args A list of arguments the function accepts.
57 | */
58 | (...args: string[]): GeneratorFunction;
59 | /**
60 | * The length of the arguments.
61 | */
62 | readonly length: number;
63 | /**
64 | * Returns the name of the function.
65 | */
66 | readonly name: string;
67 | /**
68 | * A reference to the prototype.
69 | */
70 | readonly prototype: GeneratorFunction;
71 | }
72 | declare var GeneratorFunction: GeneratorFunctionConstructor;
73 |
--------------------------------------------------------------------------------
/src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.codefix {
3 | registerCodeFix({
4 | errorCodes: [Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class.code],
5 | getCodeActions: (context: CodeFixContext) => {
6 | const sourceFile = context.sourceFile;
7 |
8 | const token = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
9 | if (token.kind !== SyntaxKind.ThisKeyword) {
10 | return undefined;
11 | }
12 |
13 | const constructor = getContainingFunction(token);
14 | const superCall = findSuperCall((constructor).body);
15 | if (!superCall) {
16 | return undefined;
17 | }
18 |
19 | // figure out if the `this` access is actually inside the supercall
20 | // i.e. super(this.a), since in that case we won't suggest a fix
21 | if (superCall.expression && superCall.expression.kind === SyntaxKind.CallExpression) {
22 | const arguments = (superCall.expression).arguments;
23 | for (let i = 0; i < arguments.length; i++) {
24 | if ((arguments[i]).expression === token) {
25 | return undefined;
26 | }
27 | }
28 | }
29 | const changeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
30 | changeTracker.insertNodeAfter(sourceFile, getOpenBrace(constructor, sourceFile), superCall, { suffix: context.newLineCharacter });
31 | changeTracker.deleteNode(sourceFile, superCall);
32 |
33 | return [{
34 | description: getLocaleSpecificMessage(Diagnostics.Make_super_call_the_first_statement_in_the_constructor),
35 | changes: changeTracker.getChanges()
36 | }];
37 |
38 | function findSuperCall(n: Node): ExpressionStatement {
39 | if (n.kind === SyntaxKind.ExpressionStatement && isSuperCall((n).expression)) {
40 | return n;
41 | }
42 | if (isFunctionLike(n)) {
43 | return undefined;
44 | }
45 | return forEachChild(n, findSuperCall);
46 | }
47 | }
48 | });
49 | }
--------------------------------------------------------------------------------
/bin/lib.es2017.string.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | interface String {
22 | /**
23 | * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
24 | * The padding is applied from the start (left) of the current string.
25 | *
26 | * @param maxLength The length of the resulting string once the current string has been padded.
27 | * If this parameter is smaller than the current string's length, the current string will be returned as it is.
28 | *
29 | * @param fillString The string to pad the current string with.
30 | * If this string is too long, it will be truncated and the left-most part will be applied.
31 | * The default value for this parameter is " " (U+0020).
32 | */
33 | padStart(maxLength: number, fillString?: string): string;
34 |
35 | /**
36 | * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
37 | * The padding is applied from the end (right) of the current string.
38 | *
39 | * @param maxLength The length of the resulting string once the current string has been padded.
40 | * If this parameter is smaller than the current string's length, the current string will be returned as it is.
41 | *
42 | * @param fillString The string to pad the current string with.
43 | * If this string is too long, it will be truncated and the left-most part will be applied.
44 | * The default value for this parameter is " " (U+0020).
45 | */
46 | padEnd(maxLength: number, fillString?: string): string;
47 | }
48 |
--------------------------------------------------------------------------------
/src/services/refactorProvider.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts {
3 | export interface Refactor {
4 | /** An unique code associated with each refactor */
5 | name: string;
6 |
7 | /** Description of the refactor to display in the UI of the editor */
8 | description: string;
9 |
10 | /** Compute the associated code actions */
11 | getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined;
12 |
13 | /** Compute (quickly) which actions are available here */
14 | getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined;
15 | }
16 |
17 | export interface RefactorContext {
18 | file: SourceFile;
19 | startPosition: number;
20 | endPosition?: number;
21 | program: Program;
22 | newLineCharacter: string;
23 | rulesProvider?: formatting.RulesProvider;
24 | cancellationToken?: CancellationToken;
25 | }
26 |
27 | export namespace refactor {
28 | // A map with the refactor code as key, the refactor itself as value
29 | // e.g. nonSuggestableRefactors[refactorCode] -> the refactor you want
30 | const refactors: Map = createMap();
31 |
32 | export function registerRefactor(refactor: Refactor) {
33 | refactors.set(refactor.name, refactor);
34 | }
35 |
36 | export function getApplicableRefactors(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
37 | let results: ApplicableRefactorInfo[];
38 | const refactorList: Refactor[] = [];
39 | refactors.forEach(refactor => {
40 | refactorList.push(refactor);
41 | });
42 | for (const refactor of refactorList) {
43 | if (context.cancellationToken && context.cancellationToken.isCancellationRequested()) {
44 | return results;
45 | }
46 | const infos = refactor.getAvailableActions(context);
47 | if (infos && infos.length) {
48 | (results || (results = [])).push(...infos);
49 | }
50 | }
51 | return results;
52 | }
53 |
54 | export function getEditsForRefactor(context: RefactorContext, refactorName: string, actionName: string): RefactorEditInfo | undefined {
55 | const refactor = refactors.get(refactorName);
56 | return refactor && refactor.getEditsForAction(context, actionName);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts:
--------------------------------------------------------------------------------
1 | /* @internal */
2 | namespace ts.codefix {
3 | registerCodeFix({
4 | errorCodes: [Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2.code],
5 | getCodeActions: getActionForClassLikeMissingAbstractMember
6 | });
7 |
8 | registerCodeFix({
9 | errorCodes: [Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1.code],
10 | getCodeActions: getActionForClassLikeMissingAbstractMember
11 | });
12 |
13 | function getActionForClassLikeMissingAbstractMember(context: CodeFixContext): CodeAction[] | undefined {
14 | const sourceFile = context.sourceFile;
15 | const start = context.span.start;
16 | // This is the identifier in the case of a class declaration
17 | // or the class keyword token in the case of a class expression.
18 | const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
19 | const checker = context.program.getTypeChecker();
20 |
21 | if (isClassLike(token.parent)) {
22 | const classDeclaration = token.parent as ClassLikeDeclaration;
23 |
24 | const extendsNode = getClassExtendsHeritageClauseElement(classDeclaration);
25 | const instantiatedExtendsType = checker.getTypeAtLocation(extendsNode);
26 |
27 | // Note that this is ultimately derived from a map indexed by symbol names,
28 | // so duplicates cannot occur.
29 | const extendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType);
30 | const abstractAndNonPrivateExtendsSymbols = extendsSymbols.filter(symbolPointsToNonPrivateAndAbstractMember);
31 |
32 | const newNodes = createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, checker);
33 | const changes = newNodesToChanges(newNodes, getOpenBraceOfClassLike(classDeclaration, sourceFile), context);
34 | if (changes && changes.length > 0) {
35 | return [{
36 | description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
37 | changes
38 | }];
39 | }
40 | }
41 |
42 | return undefined;
43 |
44 | }
45 |
46 | function symbolPointsToNonPrivateAndAbstractMember(symbol: Symbol): boolean {
47 | const decls = symbol.getDeclarations();
48 | Debug.assert(!!(decls && decls.length > 0));
49 | const flags = getModifierFlags(decls[0]);
50 | return !(flags & ModifierFlags.Private) && !!(flags & ModifierFlags.Abstract);
51 | }
52 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.5.0-alpha",
3 | "compilerOptions": {
4 | "target": "es5",
5 | "module": "commonjs",
6 | "jsx": "react",
7 | "declaration": false,
8 | "noImplicitAny": false,
9 | "removeComments": true,
10 | "noLib": false,
11 | "preserveConstEnums": true,
12 | "suppressImplicitAnyIndexErrors": true
13 | },
14 | "filesGlob": [
15 | "./**/*.ts",
16 | "./**/*.tsx",
17 | "!./bin/**/*",
18 | "!./TypeScript/**",
19 | "!./node_modules/**",
20 | "!./tests/grunt/**"
21 | ],
22 | "files": [
23 | "./extensions/addExtensions.ts",
24 | "./register.ts",
25 | "./src/compiler/binder.ts",
26 | "./src/compiler/checker.ts",
27 | "./src/compiler/commandLineParser.ts",
28 | "./src/compiler/core.ts",
29 | "./src/compiler/declarationEmitter.ts",
30 | "./src/compiler/diagnosticInformationMap.generated.ts",
31 | "./src/compiler/emitter.ts",
32 | "./src/compiler/parser.ts",
33 | "./src/compiler/program.ts",
34 | "./src/compiler/scanner.ts",
35 | "./src/compiler/sys.ts",
36 | "./src/compiler/tsc.ts",
37 | "./src/compiler/types.ts",
38 | "./src/compiler/utilities.ts",
39 | "./src/extensions.ts",
40 | "./src/services/breakpoints.ts",
41 | "./src/services/formatting/formatting.ts",
42 | "./src/services/formatting/formattingContext.ts",
43 | "./src/services/formatting/formattingRequestKind.ts",
44 | "./src/services/formatting/formattingScanner.ts",
45 | "./src/services/formatting/references.ts",
46 | "./src/services/formatting/rule.ts",
47 | "./src/services/formatting/ruleAction.ts",
48 | "./src/services/formatting/ruleDescriptor.ts",
49 | "./src/services/formatting/ruleFlag.ts",
50 | "./src/services/formatting/ruleOperation.ts",
51 | "./src/services/formatting/ruleOperationContext.ts",
52 | "./src/services/formatting/rules.ts",
53 | "./src/services/formatting/rulesMap.ts",
54 | "./src/services/formatting/rulesProvider.ts",
55 | "./src/services/formatting/smartIndenter.ts",
56 | "./src/services/formatting/tokenRange.ts",
57 | "./src/services/navigateTo.ts",
58 | "./src/services/navigationBar.ts",
59 | "./src/services/outliningElementsCollector.ts",
60 | "./src/services/patternMatcher.ts",
61 | "./src/services/services.ts",
62 | "./src/services/shims.ts",
63 | "./src/services/signatureHelp.ts",
64 | "./src/services/utilities.ts",
65 | "./tasks/ntypescript.ts",
66 | "./tests/tse/1start.ts",
67 | "./tests/tse/2iwillfork.ts",
68 | "./tests/tse/3iwilllogargs.ts",
69 | "./tse.ts",
70 | "./typings/gruntjs/gruntjs.d.ts",
71 | "./typings/node/node.d.ts",
72 | "./typings/tsd.d.ts"
73 | ]
74 | }
75 |
--------------------------------------------------------------------------------
/bin/lib.es2015.collection.d.ts:
--------------------------------------------------------------------------------
1 | /*! *****************************************************************************
2 | Copyright (c) Microsoft Corporation. All rights reserved.
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 | this file except in compliance with the License. You may obtain a copy of the
5 | License at http://www.apache.org/licenses/LICENSE-2.0
6 |
7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10 | MERCHANTABLITY OR NON-INFRINGEMENT.
11 |
12 | See the Apache Version 2.0 License for specific language governing permissions
13 | and limitations under the License.
14 | ***************************************************************************** */
15 |
16 |
17 |
18 | ///
19 |
20 |
21 | interface Map {
22 | clear(): void;
23 | delete(key: K): boolean;
24 | forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: any): void;
25 | get(key: K): V | undefined;
26 | has(key: K): boolean;
27 | set(key: K, value: V): this;
28 | readonly size: number;
29 | }
30 |
31 | interface MapConstructor {
32 | new (): Map;
33 | new (entries?: [K, V][]): Map;
34 | readonly prototype: Map;
35 | }
36 | declare var Map: MapConstructor;
37 |
38 | interface ReadonlyMap {
39 | forEach(callbackfn: (value: V, key: K, map: ReadonlyMap) => void, thisArg?: any): void;
40 | get(key: K): V | undefined;
41 | has(key: K): boolean;
42 | readonly size: number;
43 | }
44 |
45 | interface WeakMap {
46 | delete(key: K): boolean;
47 | get(key: K): V | undefined;
48 | has(key: K): boolean;
49 | set(key: K, value: V): this;
50 | }
51 |
52 | interface WeakMapConstructor {
53 | new (): WeakMap