* Add declaration emit error and checking for circularly referential unions produced by recursive conditionals
* Allow indexed accesses to produce alias symbols on types
* Add test that still triggers the declaration emit error
* Fix spelling
I ran into it and the comment at the top tripped me, then I proceeded to
simplify the code. Patched a bit more of the function to make sure that
the indentation doesn't change, and added tests.
Two problems are fixed:
* `isArgumentsLocalBinding` did only `PropertyAccessExpression`, now
it's also doing `PropertyAssignment` (doesn't affect other files,
since it's only used in the emitter).
* `visitShorthandPropertyAssignment` should call `visitIdentifier` on
the synthesized id. (For completion it might be better to make it
visit the the original?)
Fixes#38594.
Neither `x[0]` nor `x[(0)]` should be dynamic names. Previously, the
latter was because `isDynamicName` didn't skip parentheses.
Since the binder treats dynamic names in property assignments as
assignment declarations, this incorrectly tried to create a binding for
expressions like `x[(0)] = 1`.
This caused an assert because `x[(0)]` would not take the dynamic name
code path during binding (`hasDynamicName` returned false), but the
normal code path for static names.
* fix(38750): create unique names for keywords and re-export them with original names
* Serialize (noncontextual) keyword named namespace members with export declarations in both declaration emitters
* Add exhaustive keyword emit test for js declaration emitter and fix it up
Co-authored-by: Alexander T <alexander.tarasyuk@outlook.com>
This completes the work that started in PR #33069, and fixes#32835.
There are probably two additional related changes that are needed to
make this more complete:
* Fix the code that composes the error message (see the first two
`FIXME`s in `callWithSpread3.ts`).
* Fix the code that checks the argument types (second two `FIXME`s).
* There is also an error in `genericRestParameters1.ts` which changed
but should not be an error in the first place. Added a `FIXME` there
too. (Probably will work if the previous iterm is done.)
In addition, `getEffectiveCallArguments` munges the arguments in case of
a spread in the last argument which might be better to avoid. (I think
that there are cases where it wouldn't work anyway, such as a spread of
an array followed by a spread of an empty array.)
* Emit buildinfo when there are errors with noEmitOnError?
TODO: --build mode
* Always emit tsbuild info even if there are non syntax errors in tsc --build mode
* Sort affectedFilesPendingEmit for consistent build info text
* add skeleton
* add getAvailableActions
* add working getEditsForAction
* add multi vardecl
* fix multi decl bug
* change refactor name
* add tests for ToAnon, ToArrow and available arrow
* add tests for ToNamed and available anon
* add tests for ReturnType and available Arrow as FnParam
* fix bug modifiers by toNamed
* add tests for modifiers
* fix for tslint error
* adapt one test case
* refactor getInfo getAvailableActions
* refactor small progress
* extract creation of block
* extract creation of funcDeclaration
* make guideline compliant
* apply feedback from pr
* add testcase and apply feedback from pr
* apply feedback from pr
* add newline
* rename testcases
* Make conditions more expressive
* fix for unnecessary duplication of comment
* apply feedback from pr
* update getAvailableActions
* check if functionExpression name is used
* add more testcases
* do not provide refactoring when it contains this
because this behaves differently in arrow than in function
* exclude nested functions and classes at containingThis check
* fix linting error
* fix line endings
Co-authored-by: BigAru <arooran@indikon.ch>
Co-authored-by: bigaru <bigaru@users.noreply.github.com>
Co-authored-by: Jesse Trinity <42591254+jessetrinity@users.noreply.github.com>
Co-authored-by: Jesse Trinity <jetrinit@microsoft.com>
* fix: range of ts2657 (jsx expr must have parent) and remove 2695 (LHS expr of comma has no side effects)
* feat: add code fix for 2657
* fix: resolve review
* chore: hoist a var
* chore: add test for skipTrivia
* fix: rebase error
* Update src/compiler/diagnosticMessages.json
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
* Update src/services/codefixes/wrapJsxInFragment.ts
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
Co-authored-by: Andrew Branch <andrew@wheream.io>
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
1. Switch to isSymbolAccessible for both types and values, then unify to
a single function.
2. Remove inaccesible base error. We can put it back after making
@implements type reference lookup looser (which may or may not happen).
* Initial draft of named tuple members
* Show tuple labels and documentation in completions
* Swap allowed syntax to parameter-like
* Add quickfix for labeled tuple syntax mistakes
* Add refactoring to convert list of signatures to single overload
* Fix small bug in visitor verification
* Signature help for rest parameters which are unions of tuples are displayed as seperate entries now
* Expand sanity check test cases in conformance suite
* Add tests and code for preserving tuple names through spreads where possible
* More refactoring tests, some comment preservation and some fixed formatting of multiline tuples
* Handle missing parameter named in isValidDeclarationForTupleLabel
* Minor text fixes
This problem was introduced in 70399e146e (from PR #23801), which added
a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`,
before that, it would fallback to the default of `visitNode`. So re-add
that happen in `processTaggedTemplateExpression`.
Since it doesn't hurt, I left a `Debug.checkDefined(property.name)`
instead of `!`-ing it.
Fixes#38558.
* Improve assert message in binder
Looking at the code, I don't think the assert can ever fire, but it
clearly does, or did in the past. This will make it easier for people to
create a repro.
* fix lint
* Use BindableStaticNameExpression not BindableStaticAccessExpression
This type does allow identifiers, but those are ruled out earlier, so I added
an assert for that case.
* feat(37782): add quick-fix action to declare a private method for names that start from underscore
* better merge order in messages json
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Allowed comment directives to be multiline
* Added tests, and perhaps fixed a test runner bug?
* I think it's going to need a consistent variable to loop over
* Used dynamically computed indexes in verifies
* Added multiline tests
* Increased flexibility for multiline comment parsing
* Undid a couple of formatting changes; removed backslashes from multiline regexp
* Added baseline tests for multiline comment skipping
Co-authored-by: Orta Therox <orta.therox@gmail.com>
* Fix `updateBinary` `operator` parameter
There is an issue in `updateBinary` where attempting to update
`operator` without updating `left` or `right` results in a silent no-op.
* Use defaulted parameter in `updateBinary`
* Adds support for looking up past Blocks in expando objects
* Adds JS tests to validate the JS parsing also works
* Get the top level block expando tests green
* Shared early couldContainTypeVariables check in instantiateType
* Defer creation of map object in createUnionOrIntersectionProperty
* Types with top-level non-generic type alias reference no type variables
* Use CFA to determine types of properties declared by this.xxx assignments
* Accept new baselines
* Also use CFA in constructor functions
* Accept new baselines
* Fix lint error
* Only widen fresh literal types in CFA of assignment to auto-typed
* Auto-typing for declared properties with no type annotation or initializer
* Add optionality if declaration includes '?' modifier
* Always use CFA for properties with no initializer in .js files
* Small fix
It's always supposed to have been this way, but I was worried about how
breaky the change would be when adding globalThisType. This PR is
experiment to see how much.
Fixes#35882 maybe
initialiser. But this is only correct when the initialiser is for a
parameter. For example:
```ts
declare let x: { s: string } | undefined;
const { s } = x;
```
This PR removes undefined from the type of a binding pattern only when
the binding pattern's parent is a parameter. This fixes the regression
from 3.8. However, it's still not the ideal fix; we should be able to
use control flow to solve this problem. Consider:
```ts
const { s }: { s: string } | undefined = { s: 'hi' }
declare function f({ s }: { s: string } | undefined = { s: 'hi' }): void
```
Neither line should have an error, but the first does in 3.8 and after
this change.
* Remove superCallShouldBeFirst error
It seems redundant since TS gives an error on any use of `this` before
super, and non-`this` uses before `super` should be fine.
Fixes#37371
* Revert "Remove superCallShouldBeFirst error"
This reverts commit 3c09153c8a.
* error except for target:"esnext" && useDefineForClassFields
* Fix use-before-def with methods on esnext+useDefineForClassFields
It was incorrectly flagging methods as used before their definition, but
this is allowed under any emit.
* Add instance function test case
* Propagate nonInferrableType in &&, || and ?? operators
* Add regression test
* Simpler solution: getTypeFacts(neverType) should return TypeFacts.None
* Add fastpath to isRelatedTo for type references
* Do not check intersections or unions to ignore propegating reference flags, properly set comparing jsx flag
* Re-remove unneeded check
* Just check for TypeFlags.Object
* Remove else clause
* Error on missing BigInt in ES2020 too.
Previously it was only on ESNext, but bigint ships in ES 2020.
There are no tests for this; passing `false` doesn't cause any tests to
fail at least.
* add tests
* Avoid circular reference in this-property assignments
To do this, don't check this-property assigments that have the
this-property of the lhs appearing somewhere on the rhs:
```js
class C {
m() {
this.x = 12
this.x = this.x + this.y
}
}
```
I tried suppressing the circularity error, but because we cache the
first type discovered for a property, this still results in an implicit
any for `x` in the previous example. It just doesn't have an error.
Fixes#35099
* Add test case + rename function
* Use isMatchingReference
This fixes two bugs in the parseJSDocCommentWorker().
1. The initial indent was calculated wrongly. It was set to the
difference between the index of the last newline or beginning of file
and the current start marker (position of /**). By calculating it
this way, the newline character itself is counted as indentation
character as well. The initial indent is used as margin for the
whole comment. The margin contains the amount of characters to skip
before the actual content or payload of a comment line. The algorithm
does not skip non-whitespace characters at the beginning of the
content, but it would strip away one whitespace character for
indented content (which does matter, if there is e.g. a Markdown
code block with indentation in the comment).
2. When reducing initial whitespace sequences of comment lines by the
remaining margin the algorithm cut off one character too much. This
might have been introduced to fix 1. It had a similar effect as 1.
Previously this was only an error when useDefineForClassFields: true,
but now it's an error for all code. This is a rare mistake to make, and
usually only occurs in code written before `readonly` was available.
Codefix to come in subsequent commits.
Get the `declaration` container just once instead of in three places.
(Minor change: one place used to start looking from
`declaration.parent`, but that shouldn't make any difference.) Also,
don't pass it to the helper functions since they're local anyway.
This only applies in JS, where `@template` tags can apply to
initialisers of variable declarations:
```js
/**
* @template T
* @returns {(b: T) => T}
*/
const seq = a => b => b
```
Fixes#36201
* Consolidated extra property check with intersections
* Fix comment
* Add tests
* Properly propagate intersectionState
* Route property check through recursive type tracking logic
* Accept new baselines
* Skip check when apparent type of source is never
* Accept new baselines
* Only check when apparent type of source is a structured type
* Fix serialisation of static class members in JS
Previously static class members would be treated the same way as expando
namespace assignments to a class:
```ts
class C {
static get x() { return 1 }
}
C.y = 12
```
This PR adds a syntactic check to the static/namespace filter that
treats symbols whose valueDeclaration.parent is a class as statics.
Fixes#37289
* fix messed-up indent
* Extract function