Skip to content

Commit

Permalink
Merge branch 'babel:main' into duplicate_function_call_in_variable_de…
Browse files Browse the repository at this point in the history
…structuring
  • Loading branch information
dan-kez committed Sep 2, 2021
2 parents b91ab34 + fce0cff commit 700c692
Show file tree
Hide file tree
Showing 157 changed files with 944 additions and 504 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -70,6 +70,8 @@ packages/babel-standalone/babel.min.js
/eslint/*/LICENSE
!/packages/babel-eslint-plugin/LICENSE
/.vscode
# local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
/.history

/dts

Expand Down
2 changes: 1 addition & 1 deletion eslint/babel-eslint-parser/src/configuration.cjs
Expand Up @@ -11,7 +11,7 @@ exports.normalizeESLintConfig = function (options) {

return {
babelOptions: { cwd: process.cwd(), ...babelOptions },
ecmaVersion,
ecmaVersion: ecmaVersion === "latest" ? 1e8 : ecmaVersion,
sourceType,
allowImportExportEverywhere,
requireConfigFile,
Expand Down
19 changes: 19 additions & 0 deletions eslint/babel-eslint-tests/test/integration/eslint/config.js
Expand Up @@ -21,4 +21,23 @@ describe("ESLint config", () => {
});
expect(messages.length).toEqual(0);
});

it('should allow ecmaVersion to be "latest"', () => {
const linter = new eslint.Linter();
linter.defineParser("@babel/eslint-parser", parser);
// ImportDeclarations result in a parser error if ecmaVersion < 2015 and sourceType != "module".
const messages = linter.verify('import { hello } from "greetings"', {
parser: "@babel/eslint-parser",
parserOptions: {
ecmaVersion: "latest",
babelOptions: {
configFile: path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../../../../babel-eslint-shared-fixtures/config/babel.config.js",
),
},
},
});
expect(messages.length).toEqual(0);
});
});
1 change: 1 addition & 0 deletions jest.config.js
Expand Up @@ -21,6 +21,7 @@ module.exports = {
"/test/helpers/",
"<rootDir>/test/warning\\.js",
"<rootDir>/build/",
"<rootDir>/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
"_browser\\.js",
],
testEnvironment: "node",
Expand Down
9 changes: 6 additions & 3 deletions packages/babel-helper-compilation-targets/src/index.ts
Expand Up @@ -154,8 +154,11 @@ function generateTargets(inputTargets: InputTargets): Targets {
return input as any as Targets;
}

function resolveTargets(queries: Browsers): Targets {
const resolved = browserslist(queries, { mobileToDesktop: true });
function resolveTargets(queries: Browsers, env?: string): Targets {
const resolved = browserslist(queries, {
mobileToDesktop: true,
env,
});
return getLowestVersions(resolved);
}

Expand Down Expand Up @@ -217,7 +220,7 @@ export default function getTargets(
}

if (browsers) {
const queryBrowsers = resolveTargets(browsers);
const queryBrowsers = resolveTargets(browsers, options.browserslistEnv);

if (esmodules === "intersect") {
for (const browser of Object.keys(queryBrowsers)) {
Expand Down
@@ -0,0 +1,37 @@
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import getTargets from "../../lib";

const currentDir = dirname(fileURLToPath(import.meta.url));

const oldEnv = process.env.BROWSERSLIST_DANGEROUS_EXTEND;

beforeAll(() => {
process.env.BROWSERSLIST_DANGEROUS_EXTEND = true;
});

afterAll(() => {
process.env.BROWSERSLIST_DANGEROUS_EXTEND = oldEnv;
});

it("pass env to configs used with extends", async () => {
const actual = getTargets(
{
browsers: [
`extends ${resolve(
currentDir,
"fixtures",
"@babel",
"browserslist-config-fixture.cjs",
)}`,
"chrome >= 71",
],
},
{
configPath: currentDir,
browserslistEnv: "custom",
},
);

expect(actual).toEqual({ chrome: "71.0.0", firefox: "75.0.0" });
});
@@ -0,0 +1,4 @@
module.exports = {
custom: ["firefox >= 75"],
defaults: ["chrome >= 5"],
};
Expand Up @@ -31,6 +31,7 @@
"devDependencies": {
"@babel/core": "workspace:*",
"@babel/helper-plugin-test-runner": "workspace:*",
"@babel/plugin-syntax-class-static-block": "^7.14.5",
"@babel/preset-env": "workspace:*"
},
"engines": {
Expand Down

0 comments on commit 700c692

Please sign in to comment.