TypeScript/CONTRIBUTING.md

207 lines
9.8 KiB
Markdown
Raw Normal View History

# Instructions for Logging Issues
## 1. Read the FAQ
Please [read the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) before logging new issues, even if you think you have found a bug.
Issues that ask questions answered in the FAQ will be closed without elaboration.
## 2. Search for Duplicates
2018-01-08 17:04:46 +01:00
[Search the existing issues](https://github.com/Microsoft/TypeScript/search?type=Issues) before logging a new one.
Some search tips:
* *Don't* restrict your search to only open issues. An issue with a title similar to yours may have been closed as a duplicate of one with a less-findable title.
* Check for synonyms. For example, if your bug involves an interface, it likely also occurs with type aliases or classes.
* Search for the title of the issue you're about to log. This sounds obvious but 80% of the time this is sufficient to find a duplicate when one exists.
* Read more than the first page of results. Many bugs here use the same words so relevancy sorting is not particularly strong.
* If you have a crash, search for the first few topmost function names shown in the call stack.
## 3. Do you have a question?
The issue tracker is for **issues**, in other words, bugs and suggestions.
If you have a *question*, please use [Stack Overflow](http://stackoverflow.com/questions/tagged/typescript), [Gitter](https://gitter.im/Microsoft/TypeScript), your favorite search engine, or other resources.
Due to increased traffic, we can no longer answer questions in the issue tracker.
## 4. Did you find a bug?
When logging a bug, please be sure to include the following:
* What version of TypeScript you're using (run `tsc --v`)
* If at all possible, an *isolated* way to reproduce the behavior
* The behavior you expect to see, and the actual behavior
You can try out the nightly build of TypeScript (`npm install typescript@next`) to see if the bug has already been fixed.
## 5. Do you have a suggestion?
We also accept suggestions in the issue tracker.
Be sure to [check the FAQ](https://github.com/Microsoft/TypeScript/wiki/FAQ) and [search](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue) first.
2016-01-30 05:34:27 +01:00
In general, things we find useful when reviewing suggestions are:
* A description of the problem you're trying to solve
* An overview of the suggested solution
* Examples of how the suggestion would work in various places
* Code examples showing e.g. "this would be an error, this wouldn't"
* Code examples showing the generated JavaScript (if applicable)
* If relevant, precedent in other languages can be useful for establishing context and expected behavior
# Instructions for Contributing Code
## Some things in general
As Typescript is a big codebase, so some might run into issues while cloning this repo. Hence, it is advisable to use
`git clone --depth=1 <remote-url>` to clone it faster.
Run `jake build` after every change. If you want to test it locally in some another project then use `node <path-to-local-typescript-folder>/built/local/tsc.js` in place of `tsc` in your project. For example, to run `tsc --watch`, use `node <path-to-local-typescript-folder>/TypeScript/built/local/tsc.js --watch`.
2014-07-16 02:13:54 +02:00
## Contributing bug fixes
2014-07-16 02:38:38 +02:00
TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved ("Milestone == Community") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort.
2014-07-16 02:13:54 +02:00
## Contributing features
2014-07-16 21:01:36 +02:00
Features (things that add new or improved functionality to TypeScript) may be accepted, but will need to first be approved (marked as "Milestone == Community" by a TypeScript coordinator with the message "Approved") in the suggestion issue. Features with language design impact, or that are adequately satisfied with external tools, will not be accepted.
2014-07-16 02:13:54 +02:00
Design changes will not be accepted at this time. If you have a design change proposal, please log a suggestion issue.
2014-07-16 02:13:54 +02:00
## Legal
2014-07-16 02:38:38 +02:00
You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright.
2014-07-16 02:13:54 +02:00
2018-07-31 18:29:02 +02:00
Please submit a Contributor License Agreement (CLA) before submitting a pull request. You may visit https://cla.microsoft.com to sign digitally. Alternatively, download the agreement ([Microsoft Contribution License Agreement.pdf](https://opensource.microsoft.com/pdf/microsoft-contribution-license-agreement.pdf)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request.
2014-07-16 02:13:54 +02:00
## Housekeeping
2014-07-16 02:13:54 +02:00
Your pull request should:
* Include a description of what your change intends to do
* Be a child commit of a reasonably recent commit in the **master** branch
* Requests need not be a single commit, but should be a linear sequence of commits (i.e. no merge commits in your PR)
* It is desirable, but not necessary, for the tests to pass at each commit
* Have clear commit messages
2014-07-16 02:13:54 +02:00
* e.g. "Refactor feature", "Fix issue", "Add tests for issue"
2014-07-16 02:13:54 +02:00
* Include adequate tests
2014-07-16 21:01:36 +02:00
* At least one test should fail in the absence of your non-test code changes. If your PR does not match this criteria, please specify why
2014-07-16 02:13:54 +02:00
* Tests should include reasonable permutations of the target fix/change
* Include baseline changes with your change
* All changed code must have 100% code coverage
2016-01-30 05:34:27 +01:00
* Follow the code conventions described in [Coding guidelines](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines)
2014-10-24 19:36:02 +02:00
* To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration
2014-07-16 02:13:54 +02:00
## Contributing `lib.d.ts` fixes
2015-11-03 02:07:14 +01:00
The library sources are in: [src/lib](https://github.com/Microsoft/TypeScript/tree/master/src/lib)
Library files in `built/local/` are updated by running
```Shell
2015-12-03 19:39:40 +01:00
jake
```
The files in `lib/` are used to bootstrap compilation and usually do not need to be updated.
2015-12-03 19:39:40 +01:00
2015-11-03 02:08:14 +01:00
#### `src/lib/dom.generated.d.ts` and `src/lib/webworker.generated.d.ts`
These two files represent the DOM typings and are auto-generated. To make any modifications to them, please submit a PR to https://github.com/Microsoft/TSJS-lib-generator
2014-07-16 02:13:54 +02:00
## Running the Tests
2015-10-19 20:49:21 +02:00
[Transforms] Merge master 06/06/2016 (#8991) * Remove check narrowing only certain types, add test showing issues with this * string literal case test * Reconcile fix with CFA work * Defaultable -> NotNarrowable to align with use * Missed a defaultable in comments * Add test for narrowing to unions of string literals * Rewrite isInStringLiteral to accomodate for unterminated strings * Refactor signatureHelp to expose helper functions * Add support for completion in string literals * Remove unused check * Use const instead of let * Fix error * Formatting changes * Use shorthand properties * Add failing test for #8738 * Sort baseline reference identifier by name * Detects assignment to internal module export clause, fixes #8738 * add SharedArrayBuffer fix * Factor out assignment op check * Add test for composite assignment * Factor out the behaviour and handles x++ and ++x * Handles ES3 default as identifier name * Fix missing else statement * isNameOfExportedDeclarationInNonES6Module * Reorder options alphabetically * Mark diagnostics, and skipDefaultLibCheck as internal * Allow an import of "foo.js" to be matched by a file "foo.ts" * Improve loadModuleFromFile code * Respond to PR comments * Respond to more PR comments * Fix test * Actually merge from master * Revert to old tryLoad implementation * Run fixupParentReferences when parsing isolated jsDocComment * initial revision of unit test support for project system in tsserver * Allow wildcard ("*") patterns in ambient module declarations * Add non-widening forms of null and undefined * Create separate control flows for property declarations with initializers * Add regression test * Allow trailing commas in function parameter and argument lists * Add tests * Remove unused variable * Add null check and CR feedback * Support shorthand ambient module declarations * Revert "Merge pull request #7235 from weswigham/narrow-all-types" This reverts commit ef0f6c8fe4f94a7e294cfe42d7025c9dca6535d5, reversing changes made to 9f087cb62ade7a879e23c229df752fc8f87d679c. * reuse the fixupParentReferences function * Improve typing of && operator with --strictNullChecks * Add test * Respond to PR comments * Respond to PR comments * Add merging tests * Use a function `stringify` to simplify calls to `JSON.stringify(xyz, undefined, 2)` * Update tests * Fix mistake * Include indent in navigation bar protocol Previously navbar01 test had indents when run in the browser but not when run from node. Now they run the same. * Remove unnecessary restrictions in property access narrowing * Fix fourslash test * Add regression test * Consider property declarations to be control flow containers * Adding regression test * Remove restriction on --target es5 and --module es6 * change type definition for Object.create * Fix signature help * Add "implicit any" warning for shorthand ambient modules * Remove trailing whitespace * Support using string values in enums for CompilerOptions in transpile methods * Remove trailing whitespace in jakefile * Make `jake runtests-browser` support test regexes with spaces For example: `jake runtests-browser t="transpile .js files"` now works. * Add another test * factor out isJsxOrTsxExtension * Move to a conformance test * Revert "Revert "Merge pull request #7235 from weswigham/narrow-all-types"" This reverts commit fc3e040c5167868ed623612e8f33fb3beedf73b1. * Use inclusive flag, as originally done, but include almost everything * Add additional tests * Respond to PR comments * Fix typo * add tests for tsserver project system * Fix test * Allow case comparison to undefined and null in strict null checking mode * Remove incorrectly added tests * check if moduleResolution when verifying that program can be reused * more tests for module resolution change and exclude * Fix linting issues * Merge JSDoc of assignments from function expressions * Allow nested assignments in type guards * Add tests * Improve order of parameter's merged jsdoc * Force LF newlines for LKG builds/non debug builds Fixes 6630 * Create intersection types in type guards for unrelated types * Split commentsFunction test into expr/decl And renumber. * Remove TODO comments * Accept new baselines * Add tests * Remove comments * Fix test helper * Recognize relative path using in outDir property (#9025) * Recognize relative path using in outDir property * Add projects tests * Add project .json files * Update baselines * Add comments * Add test case The test passes in 1.8 and fails in master. * Return trace when exception happens * Remove Long-Done TODO AFAIK, the harness sources have been concatenated into `run.js` for as long as I've known. This stops executing them twice (and in turn makes debugging tests much easier, since you no longer have to debug into eval'd code). * Allow primitive type guards with typeof on right Previously, only type guards of the form `typeof x === 'string'` were allowed. Now you can write `'string' === typeof x`. * Primitive type guards are now order independent * Fix comments in tests * Add handleing for classes * Add more tests for target=es5 module=es6 * addExportToArgumentListKind * Accept baseline * Add more tests * wip-fixing transforms * Adds progress indicators to the runtests-parallel build task. * Fixed typo * Fix comment * Add test for out-of-range error * Use proper method of not resolving alias * Fix module loading error (commandLineOptions_stringToEnum would be undefined if optionDeclarations wasn't loaded yet) * Port 8739 * Update tests * Update baselines * Contextually type return statement in async function * Remove stale files * Undo change * Improve perf * Improve tests * Fix sourcemaps for debugging tests * Allow --sourceRoot with --inlineSources option Fixes #8445 * this in parameter initializers resolves to class Accept baselines now that the test passes. * Add tests for more kinds of import/export * Fix7334 Disallow async in functionExpression and ArrowFunction (#9062) * Error when using async modifier in function-expression and arrow-function when target es5 * Add tests and baselines * Resolve function-this in parameter initialisers when explicitly provided * Allow null/undefined guard with null/undefined on left Also add a test with baselines. * Code review comments * Update more diagnostic messages ES6->2015 Fix #8996 CC @mhegazy. * Fixes an issue with runtests-parallel when global mocha is not installed. * Update LKG * Add tests * fix baselines * Recommend runtests-parallel in CONTRIBUTING * Only inlineSourceMap when debugging through jake-browser (#9080) * Only inlineSourceMap when debugging through jake-browser * Address PR: fix typo in opt's property * Manually port tests from PR 8470 * minor fix: add missing return clause * Support using string values in enums for CompilerOptions in transpile methods * Support using string values in enums for CompilerOptions in transpile methods # Conflicts: # tests/cases/unittests/transpile.ts * Fix test helper * Add test for out-of-range error * Fix module loading error (commandLineOptions_stringToEnum would be undefined if optionDeclarations wasn't loaded yet) * Use camel-case instead of snake-case (#9134) * Manually add tests for PR 8988 * Allow wildcard ("*") patterns in ambient module declarations * Respond to PR comments * Add another test * Improve perf * Improve tests * Update baseline from merging with master * Address PR comment * Update baseline * Refactor how we retrieve binding-name cache in module transformer * Temporary accept so we get a clean run-tests result
2016-06-14 20:36:57 +02:00
To run all tests, invoke the `runtests-parallel` target using jake:
2014-07-16 02:40:28 +02:00
```Shell
[Transforms] Merge master 06/06/2016 (#8991) * Remove check narrowing only certain types, add test showing issues with this * string literal case test * Reconcile fix with CFA work * Defaultable -> NotNarrowable to align with use * Missed a defaultable in comments * Add test for narrowing to unions of string literals * Rewrite isInStringLiteral to accomodate for unterminated strings * Refactor signatureHelp to expose helper functions * Add support for completion in string literals * Remove unused check * Use const instead of let * Fix error * Formatting changes * Use shorthand properties * Add failing test for #8738 * Sort baseline reference identifier by name * Detects assignment to internal module export clause, fixes #8738 * add SharedArrayBuffer fix * Factor out assignment op check * Add test for composite assignment * Factor out the behaviour and handles x++ and ++x * Handles ES3 default as identifier name * Fix missing else statement * isNameOfExportedDeclarationInNonES6Module * Reorder options alphabetically * Mark diagnostics, and skipDefaultLibCheck as internal * Allow an import of "foo.js" to be matched by a file "foo.ts" * Improve loadModuleFromFile code * Respond to PR comments * Respond to more PR comments * Fix test * Actually merge from master * Revert to old tryLoad implementation * Run fixupParentReferences when parsing isolated jsDocComment * initial revision of unit test support for project system in tsserver * Allow wildcard ("*") patterns in ambient module declarations * Add non-widening forms of null and undefined * Create separate control flows for property declarations with initializers * Add regression test * Allow trailing commas in function parameter and argument lists * Add tests * Remove unused variable * Add null check and CR feedback * Support shorthand ambient module declarations * Revert "Merge pull request #7235 from weswigham/narrow-all-types" This reverts commit ef0f6c8fe4f94a7e294cfe42d7025c9dca6535d5, reversing changes made to 9f087cb62ade7a879e23c229df752fc8f87d679c. * reuse the fixupParentReferences function * Improve typing of && operator with --strictNullChecks * Add test * Respond to PR comments * Respond to PR comments * Add merging tests * Use a function `stringify` to simplify calls to `JSON.stringify(xyz, undefined, 2)` * Update tests * Fix mistake * Include indent in navigation bar protocol Previously navbar01 test had indents when run in the browser but not when run from node. Now they run the same. * Remove unnecessary restrictions in property access narrowing * Fix fourslash test * Add regression test * Consider property declarations to be control flow containers * Adding regression test * Remove restriction on --target es5 and --module es6 * change type definition for Object.create * Fix signature help * Add "implicit any" warning for shorthand ambient modules * Remove trailing whitespace * Support using string values in enums for CompilerOptions in transpile methods * Remove trailing whitespace in jakefile * Make `jake runtests-browser` support test regexes with spaces For example: `jake runtests-browser t="transpile .js files"` now works. * Add another test * factor out isJsxOrTsxExtension * Move to a conformance test * Revert "Revert "Merge pull request #7235 from weswigham/narrow-all-types"" This reverts commit fc3e040c5167868ed623612e8f33fb3beedf73b1. * Use inclusive flag, as originally done, but include almost everything * Add additional tests * Respond to PR comments * Fix typo * add tests for tsserver project system * Fix test * Allow case comparison to undefined and null in strict null checking mode * Remove incorrectly added tests * check if moduleResolution when verifying that program can be reused * more tests for module resolution change and exclude * Fix linting issues * Merge JSDoc of assignments from function expressions * Allow nested assignments in type guards * Add tests * Improve order of parameter's merged jsdoc * Force LF newlines for LKG builds/non debug builds Fixes 6630 * Create intersection types in type guards for unrelated types * Split commentsFunction test into expr/decl And renumber. * Remove TODO comments * Accept new baselines * Add tests * Remove comments * Fix test helper * Recognize relative path using in outDir property (#9025) * Recognize relative path using in outDir property * Add projects tests * Add project .json files * Update baselines * Add comments * Add test case The test passes in 1.8 and fails in master. * Return trace when exception happens * Remove Long-Done TODO AFAIK, the harness sources have been concatenated into `run.js` for as long as I've known. This stops executing them twice (and in turn makes debugging tests much easier, since you no longer have to debug into eval'd code). * Allow primitive type guards with typeof on right Previously, only type guards of the form `typeof x === 'string'` were allowed. Now you can write `'string' === typeof x`. * Primitive type guards are now order independent * Fix comments in tests * Add handleing for classes * Add more tests for target=es5 module=es6 * addExportToArgumentListKind * Accept baseline * Add more tests * wip-fixing transforms * Adds progress indicators to the runtests-parallel build task. * Fixed typo * Fix comment * Add test for out-of-range error * Use proper method of not resolving alias * Fix module loading error (commandLineOptions_stringToEnum would be undefined if optionDeclarations wasn't loaded yet) * Port 8739 * Update tests * Update baselines * Contextually type return statement in async function * Remove stale files * Undo change * Improve perf * Improve tests * Fix sourcemaps for debugging tests * Allow --sourceRoot with --inlineSources option Fixes #8445 * this in parameter initializers resolves to class Accept baselines now that the test passes. * Add tests for more kinds of import/export * Fix7334 Disallow async in functionExpression and ArrowFunction (#9062) * Error when using async modifier in function-expression and arrow-function when target es5 * Add tests and baselines * Resolve function-this in parameter initialisers when explicitly provided * Allow null/undefined guard with null/undefined on left Also add a test with baselines. * Code review comments * Update more diagnostic messages ES6->2015 Fix #8996 CC @mhegazy. * Fixes an issue with runtests-parallel when global mocha is not installed. * Update LKG * Add tests * fix baselines * Recommend runtests-parallel in CONTRIBUTING * Only inlineSourceMap when debugging through jake-browser (#9080) * Only inlineSourceMap when debugging through jake-browser * Address PR: fix typo in opt's property * Manually port tests from PR 8470 * minor fix: add missing return clause * Support using string values in enums for CompilerOptions in transpile methods * Support using string values in enums for CompilerOptions in transpile methods # Conflicts: # tests/cases/unittests/transpile.ts * Fix test helper * Add test for out-of-range error * Fix module loading error (commandLineOptions_stringToEnum would be undefined if optionDeclarations wasn't loaded yet) * Use camel-case instead of snake-case (#9134) * Manually add tests for PR 8988 * Allow wildcard ("*") patterns in ambient module declarations * Respond to PR comments * Add another test * Improve perf * Improve tests * Update baseline from merging with master * Address PR comment * Update baseline * Refactor how we retrieve binding-name cache in module transformer * Temporary accept so we get a clean run-tests result
2016-06-14 20:36:57 +02:00
jake runtests-parallel
```
2014-07-16 02:13:54 +02:00
2014-09-04 18:47:32 +02:00
This run will all tests; to run only a specific subset of tests, use:
2014-07-16 02:40:28 +02:00
```Shell
jake runtests tests=<regex>
```
2014-07-16 02:40:28 +02:00
2014-07-16 02:13:54 +02:00
e.g. to run all compiler baseline tests:
2014-07-16 02:40:28 +02:00
```Shell
jake runtests tests=compiler
```
2014-07-16 02:40:28 +02:00
2015-10-17 20:38:55 +02:00
or to run a specific test: `tests\cases\compiler\2dArrays.ts`
2014-07-16 02:40:28 +02:00
```Shell
jake runtests tests=2dArrays
```
2014-07-16 02:13:54 +02:00
2015-10-17 20:38:55 +02:00
## Debugging the tests
2015-10-19 20:49:21 +02:00
To debug the tests, invoke the `runtests-browser` task from jake.
2015-10-17 20:38:55 +02:00
You will probably only want to debug one test at a time:
```Shell
jake runtests-browser tests=2dArrays
```
You can specify which browser to use for debugging. Currently Chrome and IE are supported:
```Shell
jake runtests-browser tests=2dArrays browser=chrome
```
2015-10-18 16:35:56 +02:00
You can debug with VS Code or Node instead with `jake runtests debug=true`:
```Shell
jake runtests tests=2dArrays debug=true
```
2014-07-16 02:13:54 +02:00
## Adding a Test
2015-10-19 20:49:21 +02:00
To add a new test case, simply place a `.ts` file in `tests\cases\compiler` containing code that exemplifies the bugfix or change you are making.
2014-07-16 02:13:54 +02:00
These files support metadata tags in the format `// @metaDataName: value`.
The supported names and values are the same as those supported in the compiler itself, with the addition of the `fileName` flag.
`fileName` tags delimit sections of a file to be used as separate compilation units.
They are useful for tests relating to modules.
See below for examples.
2014-07-16 02:13:54 +02:00
**Note** that if you have a test corresponding to a specific spec compliance item, you can place it in `tests\cases\conformance` in an appropriately-named subfolder.
2014-07-16 02:38:38 +02:00
**Note** that filenames here must be distinct from all other compiler testcase names, so you may have to work a bit to find a unique name if it's something common.
2014-07-16 02:13:54 +02:00
2015-06-08 21:00:34 +02:00
### Tests for multiple files
When one needs to test for scenarios which require multiple files, it is useful to use the `fileName` metadata tag as such:
```TypeScript
2015-06-08 20:58:59 +02:00
// @fileName: file1.ts
export function f() {
}
2015-06-08 20:58:59 +02:00
// @fileName: file2.ts
import { f as g } from "file1";
var x = g();
```
One can also write a project test, but it is slightly more involved.
2014-07-16 02:13:54 +02:00
## Managing the Baselines
Compiler testcases generate baselines that track the emitted `.js`, the errors produced by the compiler, and the type of each expression in the file. Additionally, some testcases opt in to baselining the source map output.
2014-07-16 02:13:54 +02:00
When a change in the baselines is detected, the test will fail. To inspect changes vs the expected baselines, use
2014-07-16 02:40:28 +02:00
```Shell
jake diff
```
2014-07-16 02:13:54 +02:00
After verifying that the changes in the baselines are correct, run
2014-07-16 02:40:28 +02:00
```Shell
jake baseline-accept
```
2014-07-16 02:13:54 +02:00
to establish the new baselines as the desired behavior. This will change the files in `tests\baselines\reference`, which should be included as part of your commit. It's important to carefully validate changes in the baselines.
## Localization
All strings the user may see are stored in [`diagnosticMessages.json`](./src/compiler/diagnosticMessages.json).
If you make changes to it, run `jake generate-diagnostics` to push them to the `Diagnostic` interface in [`diagnosticInformationMap.generated.ts`](./src/compiler/diagnosticInformationMap.generated.ts).
See [coding guidelines on diagnostic messages](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-messages).