Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type casting and type assertion with Ember modules APIs #343

Merged
merged 1 commit into from
May 29, 2020

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented May 29, 2020

The prior fix for TypeScript support avoids modifying any node who's parent node's type starts with TS. This fixed a large number of scenarios where an identifier happened to be both a type and a value.

Unfortunately, there are some cases where the parent node is a TS* node but the node still needs to be transpiled to use the Ember global paths. For example:

import { addObserver } from '@ember/object/observers';
(addObserver as any)();

In this the parent node of that addObserver reference is a TSAsExpression, but we do need to transpile it to Ember.addObserver.

And:

import { addObserver } from '@ember/object/observers';
addObserver!();

In this the parent node of that addObserver reference is a TSNonNullExpression, but we do need to transpile it to Ember.addObserver.

After reviewing the @babel/plugin-transform-typescript implementation (see here) it seems that all of the other TS* style node types are directly removed (e.g. path.remove()).

Fixes #341

The prior fix for TypeScript support avoids modifying any node who's
parent node's type starts with `TS`. This fixed a large number of
scenarios where an identifier _happened_ to be both a type and a value.

Unfortunately, there are some cases where the parent node is a `TS*`
node but the node still needs to be transpiled to use the Ember global
paths. For example:

```ts
import { addObserver } from '@ember/object/observers';
(addObserver as any)();
```

In this the parent node of that `addObserver` reference is a
`TSAsExpression`, but we **do** need to transpile it to
`Ember.addObserver`.

And:

```ts
import { addObserver } from '@ember/object/observers';
addObserver!();
```

In this the parent node of that `addObserver` reference is a
`TSNonNullExpression`, but we **do** need to transpile it to
`Ember.addObserver`.

After reviewing the `@babel/plugin-transform-typescript` implementation
([see
here](https://github.com/babel/babel/blob/v7.10.0/packages/babel-plugin-transform-typescript/src/index.js))
it seems that all of the other `TS*` style node types are directly
removed (e.g. `path.remove()`).
@rwjblue rwjblue added the bug label May 29, 2020
@rwjblue rwjblue merged commit 5bdef5a into master May 29, 2020
@rwjblue rwjblue deleted the more-ts-fixes branch May 29, 2020 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReferenceError: addObserver is not defined after 7.20.2 update
1 participant