Skip to content

Commit

Permalink
use babel for extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jordonbiondo committed Jul 26, 2019
1 parent 4b3e6e7 commit f31873a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 995 deletions.
43 changes: 20 additions & 23 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

var cheerio = require('cheerio');
var Po = require('pofile');
var babylon = require('babylon');
var tsParser = require('@typescript-eslint/parser');
var babelParser = require('@babel/parser');
var search = require('binary-search');
var _ = require('lodash');

Expand Down Expand Up @@ -198,28 +197,26 @@ var Extractor = (function () {
var syntax;
var extension = filename.split('.').pop();
try {
if (extension === 'ts' || extension === 'tsx') {
syntax = tsParser.parse(src, {
sourceType: 'module',
comment: true,
ecmaFeatures: {
jsx: extension === 'tsx'
}
});
} else {
syntax = babylon.parse(src, {
sourceType: 'module',
plugins: [
'jsx',
'objectRestSpread',
'decorators',
'classProperties',
'exportExtensions',
'functionBind',
'dynamicImport'
]
});
var plugins = (extension === 'ts' || extension === 'tsx') ?
['typescript'] :
[
'jsx',
'objectRestSpread',
'decorators-legacy',
'classProperties',
'exportExtensions',
'functionBind',
'dynamicImport'
];

if (extension === 'tsx') {
plugins.push('jsx');
}

syntax = babelParser.parse(src, {
sourceType: 'module',
plugins: plugins
});
} catch (err) {
var errMsg = 'Error parsing';
if (filename) {
Expand Down
Loading

0 comments on commit f31873a

Please sign in to comment.