diff --git a/__tests__/index-test.js b/__tests__/index-test.js index 4d21287..8b53535 100644 --- a/__tests__/index-test.js +++ b/__tests__/index-test.js @@ -308,4 +308,46 @@ describe('when used with typescript', () => { expect(actual).toEqual(``); }); + + it('works when type casting', () => { + let source = ` + import { addObserver } from '@ember/object/observers'; + (addObserver as any)(); + `; + + let actual = transform7(source, [ + '@babel/plugin-transform-typescript', + Plugin, + ]); + + expect(actual).toEqual(`Ember.addObserver();`); + }); + + it('works for type assertions', () => { + let source = ` + import { addObserver } from '@ember/object/observers'; + addObserver(); + `; + + let actual = transform7(source, [ + '@babel/plugin-transform-typescript', + Plugin, + ]); + + expect(actual).toEqual(`Ember.addObserver();`); + }); + + it('works for non-null expression', () => { + let source = ` + import { addObserver } from '@ember/object/observers'; + addObserver!(); + `; + + let actual = transform7(source, [ + '@babel/plugin-transform-typescript', + Plugin, + ]); + + expect(actual).toEqual(`Ember.addObserver();`); + }); }); diff --git a/src/index.js b/src/index.js index 4c41215..682ec68 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,14 @@ function isBlacklisted(blacklist, importPath, exportName) { module.exports = function (babel) { const t = babel.types; - const isTypescriptNode = (node) => node.type.startsWith('TS'); + const TSTypesRequiringModification = [ + 'TSAsExpression', + 'TSTypeAssertion', + 'TSNonNullExpression', + ]; + const isTypescriptNode = (node) => + node.type.startsWith('TS') && + !TSTypesRequiringModification.includes(node.type); const GLOBALS_MAP = new Map();