Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove lodash dependency from tsx parser
  • Loading branch information
JHilker authored and Daniel15 committed Jun 23, 2021
1 parent 1ebebcf commit c87ebba
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -58,6 +58,7 @@
"roots": [
"src",
"bin",
"parser",
"sample"
]
}
Expand Down
8 changes: 8 additions & 0 deletions parser/__tests__/.eslintrc
@@ -0,0 +1,8 @@
{
"globals": {
"jest": true
},
"env": {
"jasmine": true
}
}
44 changes: 44 additions & 0 deletions parser/__tests__/__snapshots__/tsx-test.js.snap
@@ -0,0 +1,44 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`tsxParser parse extends the ts config with jsx support 1`] = `
Array [
"\\"mock content\\";",
Object {
"allowImportExportEverywhere": true,
"allowReturnOutsideFunction": true,
"plugins": Array [
"jsx",
"asyncGenerators",
"bigInt",
"classPrivateMethods",
"classPrivateProperties",
"classProperties",
"decorators-legacy",
"doExpressions",
"dynamicImport",
"exportDefaultFrom",
"exportExtensions",
"exportNamespaceFrom",
"functionBind",
"functionSent",
"importMeta",
"nullishCoalescingOperator",
"numericSeparator",
"objectRestSpread",
"optionalCatchBinding",
"optionalChaining",
Array [
"pipelineOperator",
Object {
"proposal": "minimal",
},
],
"throwExpressions",
"typescript",
],
"sourceType": "module",
"startLine": 1,
"tokens": true,
},
]
`;
27 changes: 27 additions & 0 deletions parser/__tests__/tsx-test.js
@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/*global jest, describe, it, expect*/

'use strict';

jest.mock('@babel/parser')
const babylon = require('@babel/parser');

const tsxParser = require('../tsx');

describe('tsxParser', function() {
describe('parse', function() {
it('extends the ts config with jsx support', function() {
const parser = tsxParser();
parser.parse('"mock content";');

expect(babylon.parse).toHaveBeenCalledTimes(1);
expect(babylon.parse.mock.calls[0]).toMatchSnapshot();
});
});
});
4 changes: 2 additions & 2 deletions parser/tsx.js
Expand Up @@ -8,11 +8,11 @@

'use strict';

const _ = require('lodash');
const babylon = require('@babel/parser');
const baseOptions = require('./tsOptions');

const options = _.merge(baseOptions, { plugins: ['jsx'] });
const options = Object.assign({}, baseOptions);
options.plugins = ['jsx'].concat(baseOptions.plugins);

/**
* Doesn't accept custom options because babylon should be used directly in
Expand Down

0 comments on commit c87ebba

Please sign in to comment.