* Add initial tests
* Add types
* Half of parsing (builds but does not pass tests)
* Parsing done; types are uglier; doesn't crash but doesn't pass
* Bind callback tag
Builds but tests still don't pass
* Only bind param tags inside callback tags
* Fix binding switch to only handle param tags once
* Checking is 1/3 done or so.
Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.
* Rename typeExpression to type (for some jsdoc)
(maybe I'll rename more later)
* Rename the rest of typeExpressions
Turns out there is a constraint in services such that they all need to
be named the same.
* Few more checker changes
* Revert "Rename the rest of typeExpressions"
This reverts commit f41a96b24d.
* Revert "Rename typeExpression to type (for some jsdoc)"
This reverts commit 7d2233a00e.
* Finish undoing typeExpression rename
* Rename and improve getTypeParametersForAliasSymbol
Plus some other small fixes
* Core checking works, but is flabbergastingly messy
I'm serious.
* Callback return types work now
* Fix crash in services
* Make github diff smaller
* Try to make github diff even smaller
* Fix rename for callback tag
* Fix nav bar for callback tag
Also clean up some now-redundant code there to find the name of typedefs.
* Handle ooorder callback tags
Also get rid of redundant typedef name code *in the binder*. It's
everywhere!
* Add ooorder callback tag test
* Parse comments for typedef/callback+display param comments
* Always export callbacks
This requires almost no new code since it is basically the same as
typedefs
* Update baselines
* Fix support for nested namespaced callbacks
And add test
* Callbacks support type parameters
1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.
* Template tags are now bound correctly
* Test oorder template tags
It works.
* Parser cleanup
* Cleanup types and utilities
As much as possible, and not as much as I would like.
* Handle callback more often in services
* Cleanup of binder and checker
* More checker cleanup
* Remove TODOs and one more cleanup
* Support parameter-less callback tags
* Remove extra bind call on template type parameters
* Bind template tag containers
Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.
* Fix fourslash failures
* Stop pre-binding js type aliases
Next up, stop pre-binding js type parameters
* Further cleanup of delayed js type alias binding
* Stop prebinding template tags too
This gets rid of prebinding entirely
* Remove TODO
* Fix lint
* Finish merge with use-jsdoc-aliases
* Update callback tag baselines
* Rename getTypeParametersForAliasSymbol
The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
* Add 'move to new file' refactor
* Code review, and support commonjs
* Compute movedSymbols completely before using, and support `export import`
* Fix assertion error: sort empty change before non-empty change
* Remove extra newline
* Add allowTextChangesInNewFiles preference
* Add the new file to 'files' in tsconfig
* Avoid parameter initializer
* Update API baselines
* Use path relative to tsconfig.json
* Code review
* Fix error where node in tsconfig file was missing a source file
* add refactor of convert private field to getter and setter
* fix refactor
* stash
* refactor accessor generate
* revert merge union type
* refeactor and accept baseline
* add support of PropertyAssignment and StringLiteral
* add support for js file
* allow static modifier in js file
* replaceNode: Always use non-adjusted end
* Never adjust start position either
* Fix excess property checks, remove unnecessary arguments
* Make 'insertText' and 'newLineCharacter' private
* Use replaceNode in one more place now that it doesn't affect comments
* Update replaceNodeRange too
* Always ask for ChangeNodeOptions
* Apply 'no-unnecessary-initializer' lint rule
Forbids `let`/`const` statements to be initialized to `undefined`, since that's the initial value by default anyway.
The auto-fixer also happened to remove two unnecessary `as number` casts in `src/harness/parallel/worker.ts`.
For historical data: to run with `--fix`, I modified the line in `Jakefile.js` that declared the `cmd` for running TSLint.
* Moved worker.ts type assertions to parameters
* Convert 'installTypesForPackge' refactor to a suggestion
* Have checker collect a list of suggestion diagnostics instead of redoing work in calculateSuggestionDiagnostics
* Add comment
* Add diagnostic even with `--allowJs`
* Use getAllowSyntheticDefaultImports to access `--allowSyntheticDefaultImport` value
* Fix#21788: Handel missing imporotClause case
* Fix#21789: Add a defensive check to forgottenThisPropertyAccess code fix for non-identifier locations
* Do not suggest prefix with `this` if the name we are looking for is diffrent from the errorLocation
* Fix#21796: Handel case of unknown module
* Add check to capture more info for #21800
* Fix#21807: check for symbol before looking up its flags
* Fix#21812: Gracefully fail if the token is not `this`.
* Make ChangeTracker#newLineCharacter public, to avoid having to pass newLineCharacter around as a parameter
* Don't require newLineCharacter as input to ChangeTracker methods, and make it private again
* Remove unnecessary wrapper classes in ts.formatting.Rule
* RulesProvider -> immutable FormatContext
* Remove Rules class, just use a list of rules
* Remove Shared namespace, replace Shared.TokenRange with TokenRange
* Simplify TokenRange
* Separate Rule and RuleSpec
* Move FormattingRequestKind to formattingContext.ts
* Simplify references
* Fix lint
* Revert removal of trailing newlines
* Use NodeFlags to detect nodes in ambient contexts instead of climbing ancestors
* Set context flags on tokens
* Remove 'isDeclarationFile' parameter to 'initializeState' and move to 'parseSourceFileWorker'
* Changes based on code review
* Update API baselines
* Add utility function to check for strict option flags
- Correctelly check for noImplicitAny in checker
- Correctelly check for noImplicitAny in installTypesForPackage refactor
* Respond to code review comments
* Accept baselines
* Revert "Accept baselines"
This reverts commit cf4ef62830.
* Move type alias to core
1. Transform index signatures to TS index signatures.
2. Print object literals on a single line.
3. Only offer the refactor when it could add types. (There must not be a
type annotation already, and there must be a JSDoc that applies.)
If there are only declarations, use the new function as the initializer
for a destructuring declaration.
If there are declarations and writes, changes all of the `const`
declarations to `let` and add `| undefined` onto any explicit types.
Use destructuring assignment to accomplish both "initialization" and
writes.
I don't believe there is a case where there are both declarations and a
return (since the declarations wouldn't be available after the return).
UNDONE: this could probably be generalized to handle binding patterns
but,
for now, only identifiers are supported.
Fixes#18242Fixes#18855
Found while updating #18285 to latest master. Not sure what this fixes, but it was definitely incorrect - `node` must be a `Block` at this point, so this cast must have been intended for `node.parent`, which was checked against `TryStatement` right before it.
1) Replace range, rather than node, to leave trivia intact.
2) Only replace node in the innermost scope - otherwise insert as usual
and delete the original statement.
Old: Insert the same Node for every occurrence. The position was
repeatedly mutated during printing.
New: Thunk the Node so that a new one is constructed for every
occurrence.
Fixes#18857
Now that we're smarter about where we declare the extracted local, we
can ignore usage problems in the innermost script - it'll always have
access to the same symbols as the extracted expression.
...mostly by putting them closer to the extraction site.
They now also follow all leading comments in a file (unfortunately,
including the doc comment on the first declaration).
Bonus: Special case declaration lists - declare the new variable as part
of the list, rather than before it, in case it depends on an earlier
entry.
1) It assumed left-associativity and was, therefore, wrong for (e.g.)
exponentiation.
2) Arguably, if a user selects `a + |b + c|`, they want to extract `b +
c`, not `a + b + c`. Not being able to do so is surprising (and we may
eventually want to allow it), but so is having the rest of the
least-common subtree extracted.
Fixes#18268
Major changes:
1) Instead of skipping undesirable scopes, include them and mark them
with errors. Constants can be extracted into more scopes.
2) Update the tests to call through the "public" API. This caused some
baseline changes.
3) Rename refactoring to "Extract Symbol" for generality.
4) Return a second ApplicableRefactorInfo for constants. Distinguish
the two by splitting the action name.
When the caret is on a Typescript declaration that has no type, but does
have a JSDoc annotation with a type, this refactor will add the
Typescript equivalent of the JSDoc type.
Notes:
1. This doesn't delete the JSDoc comment or delete parts of it. In fact,
due to bugs in trivia handling, it sometimes duplicates the comment.
These bugs are tracked in #18626.
2. As a bonus, when `noImplicitAny: true`, this shows up as a code fix in VS Code
whenever there is a no-implicit-any error. With `noImplicityAny: false`,
this code must be invoked via the refactoring command.
The emitter expects undefined, rather than empty. This only affects JS,
because TS applies `private` to all extracted methods.
(cherry picked from commit 9630c46ea7)
...correctly in a containing scope. It's not an issue because we'll
just declare a corresponding type parameter on the extracted function
and pass the original as a type argument.
Fixes#18142
* extractMethod: Support renameLocation
* Add tslint disable
* Properly analyze list of changes to always get a correct rename location
* Update test
* Ensure name is really unique
* Improvements to test code
* Respond to PR comments
1. It was looking at the parent which wasn't guaranteed to be in the
extracted range.
2. It was checking direct, rather than indirect containment - apparently
to avoid applying the rules to certain expressions (which can't contain
jumps anyway, unless they're in anonymous functions, in which case
they're fine).
Fixes#18144
* Ensure that emitter calls calbacks
* Move new parameter to end of parameters
* Fix for ConditionalExpression
* Make suggested changes to emitter
* Fix parameter ordering
* Respond to minor comments
* Remove potentially expensive assertion
* More emitter cleanup
Known limitations:
1. If a type parameter on an inner symbol shadows a type parameter on an
outer symbol, the generated code will be incorrect. We should either
rename one or more type parameters or forbid the extraction.
2. Type arguments are always passed explicitly, even if they would be
inferred correctly.
* Test for action description of code actions, and simplify description for extracting method to file
* Add unit test file missing from tsconfig.json (only affects gulp) and update tests
* Use the actual number
* Use "module scope" or "global scope" instead of "this file"
* Created a branded type for escaped strings
Then flowed it throughout the compiler, finding and fixing a handful of
bugs relating to underscore-prefixed identifiers in the process.
Includes a test for two cases noticed - diagnostics from conflicting
symbols from export *'s, and enum with underscore prefixed member emit.
* Correctly double underscores WRT mapped types
* Add fourslash tests for other fixed issues
* use function call over cast
* Update forEachEntry type accuracy
* Just use escaped names for ActiveLabel
* Remove casts from getPropertyNameForPropertyNameNode
* This pattern has occurred a few times, could use a helper function.
* Remove duplicated helper
* Remove unneeded check, use helper
* Identifiers list is no longer escaped strings
* Extract repeated string-getting code into helper
* Rename type and associated functions
* Make getName() return UnderscoreEscapedString, add getUnescapedName()
* Add list of internal symbol names to escaped string type to cut back on casting
* Remove outdated comments
* Reassign interned values to nodes, just in case
* Swap to string enum
* Add deprecated aliases to escapeIdentifier and unescapeIdentifier
* Add temp var
* Remove unsafe casts
* Rename escaped string type as per @sandersn's suggestion, fix string enum usages
* Reorganize double underscore tests
* Remove jfreeman from TODO
* Remove unneeded parenthesis