* Allow `override` as parameter property
* Update other baseline
* Add test for override on normal parameter
* Copy typo fix
* Update baselines
* Update API baseline
* Instantiate getter when infering setter parameter value
* Use esnext on tests
* Instantiate for JsDoc and getter from body
* PR comments
* Updated baseline
JSDoc typedefs don't actually have hosts, because they're not
semantically attached to a declaration. However, the parser still
attaches them to some declaration (or statement), but that declaration
is not related to the typedef.
Previously, delayedBindJSDocTypedefTag used getJSDocHost to walk past
the unrelated declaration, but #41858 correctly started categorising
typedefs as unattached, with no host, so the binder began falling
back to file scope.
The path to skip the unrelated declaration is always the same, though, so this
PR uses `typeAlias.parent.parent` instead of `getJSDocHost(typeAlias)`.
* Add jsdoc to if statements
This should only happen in JS files, however, and there needs to be some
conditional handling of jsdoc on statements that can't have jsdoc in TS
files.
* Finish change
* Add test
* Corrected parsing for decorators on 'this' parameters
* Moved checking to parser and added a specific test
* Remove unrelated checker.ts blank line
* Missed some baseeline updates...
* If target:esnext,then useDefineForClassFields: true will now be the default.
* Added error if a private identifier is used in a static a initializer if target:ESNext and useDefineForClassFields:false.
* Added test for new useDefineForClassFields default and error message.
* Fixed tests after changing the default of useDefineForClassFields to true for target esnext
* Fixed code review suggestions.
* Updated error message.
* Added missing static check for the containing property. Fixed other code review issues.
* Allow redeclaring CommonJS alias with initial undefined
This allows us to read our own output, plus the times when people
manually write exactly the same pattern.
Fixes#40555
* Use control flow to type commonjs exports
1. Could probably use a *lot* more tests.
2. getTypeOfAlias redoes some work from resolveAlias because it needs to
not resolve the alias completely, just to its export.
* fix lint, improve jsdoc
* Add tests, improve+fix control flow
1. Update the module.exports test to match the exports ones.
2. Add a test of evolving commonjs type.
3. Add a test of assignment as last statement.
(1) exposed a bug that required a better synthetic reference. (3)
exposed a bug that was most easily fixed by giving source files a
`endFlowNode` like functions and setting it in the binder.
* fix lint
* Added support for private identifier methods.
* Added tests for private methods.
* Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.
* Added private accessors tests
* Transform private methods
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Rename shouldTransformPrivateFields
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Use a single WeakSet for brand-check
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add a test for using private methods in static field initializers
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add breaking checker test
Private methods inside class expressions should not error.
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add to instances once per-instance
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: evaluate receiver and rhs expressions before throwing on readonly assignment
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Add a test for evaluating rhs before readonly assignment
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Transpile private accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: handle readonly/writeonly accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* accept baseline
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for private setter without a getter
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: getAllUnscopedEmitHelpers
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: better handling of duplicate names
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Fixed wrong error message for private methods in class expressions.
* change error message
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for async private methods with a higher target
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: setter assignment returns rhs value
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for setter assignment return value
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: handle duplicate accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add tests for duplicate accessors
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* docs: add missing parameter docs
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Fixed failing test.
* baseline-accept: ordering changes
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* fix: attach weakSetName to property declaration
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test for nested private methods
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* add a test with any
Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Added support for static private fields accessors and methods.
* Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet.
* Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check.
* Added tests for private static fields methods and accessors.
* Fixed error messages and tests after merge.
* Accept new baseline.
* Improved duplicate identifier checks for static private class elements.
* Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext.
* Fixed code review issues.
* Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext`
* Changed emit for uninitialized private static fields.
* Added runtime error in helper if a static private field is accessed before it was declared.
* Fixed code review comments for private identifier static class elements.
* add debug.assertNever for unknown node type (#53)
* Fixed code review issues.
* Fixed code review issues for private class elements.
* Fixes class shadowing when checking access to a private static class element.
* fix private methods/accessors in class expr inside a loop
* collapse switch case
* fix class name
* simplify getPrivateMethodsAndAccessors
* remove findPreviousAccessorInfo
* lazily create weakSetName identifier
* do not allocate a node if not needed in visitMehodDeclaration (#55)
* Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job.
* Simplified emit for private identifier class elements.
* do not clone the receiver (#57)
* leave bad code in for #constructor and duplicate private names (#58)
* Added check for WeakSet collision.
* Added error for using a set only accessor.
* update keyof tests and ?? (#62)
* replace ?? with ||
* update keyof tests
* fix emit helpers comments
* produce an error if private field helpers are not up to date
* add tests
* fix setter-only compound assignment
* fix tests
* fix duplicated trailing comments (#64)
* clear receiver pos and setTextRange on helper calls
Co-authored-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
* Revert "Revert "Editor support for link tag (#41877)" (#43302)"
This reverts commit 451d4354b9.
* Fix parsing @link at end of comment
* Parse comments as string when no @link occurs
* fix lint
* Narrow type variables with union constraints when merited by contextual type
* Narrow generics with union type constraints as indicated by contextual type
* Accept new baselines
* Add tests
* Fix circularity for JSX elements
* Remove unnecessary isConstraintPosition information from flow cache key
* Update comment
* Add additional tests
* Rename to getNarrowableTypeForReference, remove getConstraintForLocation
* Add comment
* Fix removal of undefined in destructurings with initializers
* Use getContextFreeTypeOfExpression in discriminateContextualTypeByObjectMembers
* In obj[x], use constraint of obj's type only when x's type is non-generic
* Add comment
* Initial scribbles
* Compiles but provides spans instead of location pairs
Probably need to fork the services/server types and provide a conversion
with Session.toFileSpan. Not sure where to put the conversion.
* Switch to DocumentSpan
In theory this is already better supported, but not sure practise bears
that out.
* Builds w/protocol types + conversions
* cleanup:better names and scrub TODOs
* fix test harness too
* Misc
1. Simplify protocol after talking to @mjbvz.
2. Add more tests.
3. Initial notes about where to add parsing.
* Parse and store links in the compiler
The text of the link is still stored in the comment text, but that's now
kept in an object instead of just a string. Each link has the parse for
the entity reference, if there is one.
Needs lots more tests -- this just makes all the existing jsdoc tests
pass.
* more tests and some fixes
* Fix other failing tests
* fix bad merge
* polish parser
* improve names and array types
* slight tweaks
* remove some done TODOs
* more tests + resulting fixes
* add+fix cross-module tests
* Support `@see {@link`
Plus find-all-refs support equivalent to @see's.
* add server test
* Make comments actually part of the AST
* Add span for link.name in language service/protocol
* Make checker optional in getJSDocTags
Also change to JSDocCommentText from JSDocCommentComment
* Use getTokenValue instead of getTokenText
Measure twice, slice once
* Add missing support for top-level links
The language service and protocol were missing support for top-level
links. This commit adds that plumbing.
* add string back to comment type in node constructors
* Full parse of link tags and jsdoc comment text
- Doesn't pass fourslash yet, I'm going to switch to baselines for
failures there.
- Still needs some work on the protocol to convert file+offset to
file+line+offset.
* fix lint
* Fix missing newlines in inferFromUsage codefix
* Parse jsdoc comments as text node/link array
And switch to line+character offsets in the protocol
* Fix fourslash tests
Mostly ones that can't be baselined, but I switched a couple more over
to baselines
* Improve types and documentation
* Test+fix @link emit, scrub other TODOs
* update API baselines
* test that goto-def works with @link
* Split link displaypart into 3
One for link prefix and suffix, one for link name, and one for link
text.
* update baselines
* Provide JSDocTagInfo.text: string to full clients by default
Instead of upgrading them to displayparts.
* Real server tests
* Disambiguate {@link} and @param x {type}
They are ambiguous; previously the parser preferred the type
interpretation, but will now look ahead and parse links instead when the
prefix is `{@link`.
* Add explanatory comment in test
* fix location in richResponse in protocol
* update API baseline
* Address PR comments
1. Add a cross-file goto-def test.
2. Switch from per-message args to UserPreference.
* use arraysEqual from core
* Fix property name bindings for class expr in loops
* Fix block-scope capturing with prop initializers
Co-authored-by: Joey Watts <joey.watts.96@gmail.com>
This was caused by the fact that getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull) will return never both if resultType was already never and if resultType does not contain undefined or null. In the latter case returning the declaring type is correct, in the former case this causes something narrowed to never to still be typed as the original declared type.
* Improve @template lookup and resilience
1. @template parsing may produce a template tag with a type parameter
whose name is the missing identifier. These tags should be skipped
in the checker because they receive an error in the parser.
2. The fix in #37819 was incorrect; there's no such thing as a type
parameter declared on a variable declaration. Instead, there needs to be a type
parameter declared on a jsdoc comment, because that's the scope for tags
like `@return` and `@typedef`.
There are 3 tests because either fix (1) and (2) fix the first test's
failure, but both are required to fix the last two tests' failures.
* remove containsParseError call
e350c357 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`. So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.
Fixes#42350
* @typedef: Improve error spans from declaration emit
This is a proof-of-concept fix. I think it could be expanded for all of
jsdoc, but I only set it up for jsdoc type aliases. It could use a lot
of polish too.
* track error node in isSymbolAccessible instead
* Switch to using enclosingDeclaration
Remove trueErrorNode
* add test of @callback and @enum
* Better error + fix @enum error
Since enums don't have a name property, you *have* to call
`getNameOfDeclaration` to go looking through the AST for one.
* Support Top Level "for await of".
* Add test cases for top level "for await of".
* Apply suggestions from code review
* add test cases
* remove redundant variables
* fix test baselines
* Update diagnostic message and tests
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
* Add support for abstract constructor types
* Add backwards-compatible overloads for creating/updating constructor types
* Reverting use of 'abstract' in lib/es5.d.ts due to eslint issues
* Update baseline due to reverting lib
* Add error for failing to mark an mixin class as abstract
* Fix declaration/quick info for abstract construct signatures
* Support starting and middle rest elements in tuples
* Accept new baselines
* Include all rest arguments in error span
* Accept new baselines
* Fix tests
* Add new tests
* Fix lint errors
* Infer template literal types for template literal expressions
* Update test
* Update another test
* Accept new baselines
* Minor fixes
* Add tests
* Accept new baselines
* Make new TypeFlags internal
* Accept new API baselines
* Ensure template literals assignable to String, Object, {}, etc.
* Add tests
* Less aggressive wildcard check, 'keyof any' constraint for 'infer T' in mapped type constraint position
* Accept new baselines
* Add regression tests
* Allow type-only ImportEqualsDeclarations
* Suppress CJS-in-ESM error when type-only
* Add grammar error on import type in import alias
* Update API baselines
* Fix importsNotUsedAsValues with ImportEqualsDeclarations
* Make bad error talk words more good for Daniel. Fixes#41603
* One more error message baseline update
* Update transformer and emitter
Fixes resolution of export aliases in the postfix-property-access case
of commonjs require:
```js
const { x } = require('./foo').nested
x
```
This program would previously fail if `x` was an export alias.
Fixes#41422
* Support xml namespace prefix for JSX elements and attributes
Just as with the `-` character, `:` is now also treated specially in JSX
element and attribute names, but is only allowed a single time, and not
at the beginning or end of the name, as is specified in the JSX spec.
All tests in jsxInvalidEsprimaTestSuite still fail, but for slightly
different reasons now. Two lines in jsxEsprimaFbTestSuite were
uncommented as they included elements with namespaces, and they now pass
without error.
* Add case for colons at ends of identifier
* Add case for jsx namepsace intrinsics
* Add cases with upcase idents for jsx namespaces
* Add case for jsx namespaces with react option
* Always consider jsx names with colon to be intrinsics
* Adjust comment about chars valid in jsx names but not js idents
* Fix minor typo in namespace prefix test case variable name
* Remove misleading comments on isUnhyphenatedJsxName