Skip to content

Fix crash on bad namespace parse#37626

Merged
sandersn merged 3 commits intomasterfrom
fix-crash-on-bad-namespace-parse
Apr 1, 2020
Merged

Fix crash on bad namespace parse#37626
sandersn merged 3 commits intomasterfrom
fix-crash-on-bad-namespace-parse

Conversation

@sandersn
Copy link
Copy Markdown
Member

global inside a class body is parsed as a module declaration, and in
the following example has no body:

class C {
  global x
}

x is parsed as a separate ExpressionStatement. This caused a crash in
emit because the code didn't expect a module declaration with no body.

Fixes #35717

`global` inside a class body is parsed as a module declaration, and in
the following example has no body:

```ts
class C {
  global x
}
```

`x` is parsed as a separate ExpressionStatement. This caused a crash in
emit because the code didn't expect a module declaration with no body.
Comment thread src/compiler/transformers/ts.ts Outdated
let statementsLocation: TextRange;
let statementsLocation: TextRange | undefined;
let blockLocation: TextRange | undefined;
const body = node.body!;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove non null assertion here given that's what you are fixing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just inlined the variable.

@sandersn sandersn merged commit 95a124f into master Apr 1, 2020
@sandersn sandersn deleted the fix-crash-on-bad-namespace-parse branch April 1, 2020 22:05
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.7.3] TypeError: Cannot read property 'kind' of undefined

3 participants