diff --git a/bin/__tests__/jscodeshift-test.js b/bin/__tests__/jscodeshift-test.js index 36289df7..4832528a 100644 --- a/bin/__tests__/jscodeshift-test.js +++ b/bin/__tests__/jscodeshift-test.js @@ -321,7 +321,27 @@ describe('jscodeshift CLI', () => { } ); }); - }) + }); + + describe('--parser=ts', () => { + it('parses TypeScript sources', () => { + const source = createTempFileWith('type Foo = string | string[];'); + const transform = createTransformWith( + 'api.jscodeshift(fileInfo.source)\nreturn "changed";' + ); + return run([ + '-t', transform, + '--parser', 'ts', + '--run-in-band', + source, + ]).then( + out => { + expect(out[0]).not.toContain('Transformation error'); + expect(readFile(source)).toEqual('changed'); + } + ); + }); + }); describe('--parser-config', () => { it('allows custom parser settings to be passed', () => { diff --git a/parser/ts.js b/parser/ts.js index 66866927..2e95e85b 100644 --- a/parser/ts.js +++ b/parser/ts.js @@ -10,7 +10,7 @@ 'use strict'; -const babylon = require('babylon'); +const babylon = require('@babel/parser'); const options = require('./tsOptions'); /** diff --git a/parser/tsx.js b/parser/tsx.js index 38770002..05171b99 100644 --- a/parser/tsx.js +++ b/parser/tsx.js @@ -11,7 +11,7 @@ 'use strict'; const _ = require('lodash'); -const babylon = require('babylon'); +const babylon = require('@babel/parser'); const baseOptions = require('./tsOptions'); const options = _.merge(baseOptions, { plugins: ['jsx'] });