Skip to content

Commit

Permalink
Update babel patch to no longer ignore optional chaining (#493)
Browse files Browse the repository at this point in the history
Progress toward #461

This doesn't update it to latest, but the current revision had a number of
usages that can be handled by Sucrase now.
  • Loading branch information
alangpierce committed Dec 29, 2019
1 parent 8b7a4f7 commit ed3995f
Showing 1 changed file with 0 additions and 155 deletions.
155 changes: 0 additions & 155 deletions example-runner/example-configs/babel.patch
Expand Up @@ -74,148 +74,6 @@ index a420748f1..7678c4796 100644
"collectCoverageFrom": [
"packages/*/src/**/*.mjs",
"packages/*/src/**/*.js",
diff --git a/packages/babel-core/src/transformation/index.js b/packages/babel-core/src/transformation/index.js
index e2eccd894..e0d501153 100644
--- a/packages/babel-core/src/transformation/index.js
+++ b/packages/babel-core/src/transformation/index.js
@@ -59,7 +59,7 @@ export function runSync(
try {
transformFile(file, config.passes);
} catch (e) {
- e.message = `${opts.filename ?? "unknown"}: ${e.message}`;
+ e.message = `${opts.filename != null ? opts.filename : "unknown"}: ${e.message}`;
if (!e.code) {
e.code = "BABEL_TRANSFORM_ERROR";
}
@@ -72,7 +72,7 @@ export function runSync(
({ outputCode, outputMap } = generateCode(config.passes, file));
}
} catch (e) {
- e.message = `${opts.filename ?? "unknown"}: ${e.message}`;
+ e.message = `${opts.filename != null ? opts.filename : "unknown"}: ${e.message}`;
if (!e.code) {
e.code = "BABEL_GENERATE_ERROR";
}
diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js
index 078cd91dc..a01ad07fc 100644
--- a/packages/babel-core/test/config-chain.js
+++ b/packages/babel-core/test/config-chain.js
@@ -7,7 +7,7 @@ import { loadOptions as loadOptionsOrig } from "../lib";
// TODO: In Babel 8, we can directly uses fs.promises which is supported by
// node 8+
const pfs =
- fs.promises ??
+ fs.promises != null ? fs.promises :
new Proxy(fs, {
get(target, name) {
if (name === "copyFile") {
diff --git a/packages/babel-helper-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js
index 64b136923..52d948427 100644
--- a/packages/babel-helper-builder-react-jsx/src/index.js
+++ b/packages/babel-helper-builder-react-jsx/src/index.js
@@ -95,7 +95,9 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
value.value = value.value.replace(/\n\s+/g, " ");

// "raw" JSXText should not be used from a StringLiteral because it needs to be escaped.
- delete value.extra?.raw;
+ if (value.extra != null) {
+ delete value.extra.raw;
+ }
}

if (t.isJSXNamespacedName(node.name)) {
diff --git a/packages/babel-helper-create-regexp-features-plugin/src/index.js b/packages/babel-helper-create-regexp-features-plugin/src/index.js
index 49554be42..412d6c909 100644
--- a/packages/babel-helper-create-regexp-features-plugin/src/index.js
+++ b/packages/babel-helper-create-regexp-features-plugin/src/index.js
@@ -24,7 +24,7 @@ export function createRegExpFeaturePlugin({ name, feature, options = {} }) {
name,
pre() {
const { file } = this;
- const features = file.get(featuresKey) ?? 0;
+ const features = file.get(featuresKey) != null ? file.get(featuresKey) : 0;
let newFeatures = enableFeature(features, FEATURES[feature]);

const { useUnicodeFlag, runtime = true } = options;
@@ -49,7 +49,7 @@ export function createRegExpFeaturePlugin({ name, feature, options = {} }) {
const { node } = path;
const { file } = this;
const features = file.get(featuresKey);
- const runtime = file.get(runtimeKey) ?? true;
+ const runtime = file.get(runtimeKey) != null ? file.get(runtimeKey) : true;
const regexpuOptions = generateRegexpuOptions(node, features);
if (regexpuOptions === null) {
return;
diff --git a/packages/babel-helper-module-transforms/src/rewrite-live-references.js b/packages/babel-helper-module-transforms/src/rewrite-live-references.js
index 8bd93f509..7514f4f5f 100644
--- a/packages/babel-helper-module-transforms/src/rewrite-live-references.js
+++ b/packages/babel-helper-module-transforms/src/rewrite-live-references.js
@@ -240,7 +240,7 @@ const rewriteReferencesVisitor = {

const exportedNames = exported.get(localName);
const importData = imported.get(localName);
- if (exportedNames?.length > 0 || importData) {
+ if ((exportedNames != null ? exportedNames.length : undefined) > 0 || importData) {
assert(path.node.operator === "=", "Path was not simplified");

const assignment = path.node;
diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js
index 89088db4d..a9e94a28c 100644
--- a/packages/babel-parser/src/parser/expression.js
+++ b/packages/babel-parser/src/parser/expression.js
@@ -876,7 +876,7 @@ export default class ExpressionParser extends LValParser {
node,
call.arguments,
true,
- call.extra?.trailingComma,
+ call.extra != null ? call.extra.trailingComma : undefined,
);
return node;
}
diff --git a/packages/babel-parser/src/parser/lval.js b/packages/babel-parser/src/parser/lval.js
index 547441b0c..66292c434 100644
--- a/packages/babel-parser/src/parser/lval.js
+++ b/packages/babel-parser/src/parser/lval.js
@@ -70,7 +70,7 @@ export default class LValParser extends NodeUtils {
if (
isLast &&
prop.type === "RestElement" &&
- node.extra?.trailingComma
+ node.extra != null ? node.extra.trailingComma : undefined
) {
this.raiseRestNotLast(node.extra.trailingComma);
}
@@ -96,7 +96,7 @@ export default class LValParser extends NodeUtils {
node.elements,
isBinding,
contextDescription,
- node.extra?.trailingComma,
+ node.extra != null ? node.extra.trailingComma : undefined,
);
break;

diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js
index ab5f646b6..aed12c839 100644
--- a/packages/babel-parser/src/plugins/flow.js
+++ b/packages/babel-parser/src/plugins/flow.js
@@ -953,7 +953,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
variance,
kind,
allowSpread,
- allowInexact ?? !exact,
+ allowInexact != null ? allowInexact : !exact,
);

if (propOrInexact === null) {
@@ -1870,7 +1870,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
((node.params: any): N.Expression[]),
true,
"arrow function parameters",
- node.extra?.trailingComma,
+ node.extra != null ? node.extra.trailingComma : undefined,
);
// Enter scope, as checkParams defines bindings
this.scope.enter(functionFlags(false, false) | SCOPE_ARROW);
diff --git a/packages/babel-parser/src/util/scopeflags.js b/packages/babel-parser/src/util/scopeflags.js
index d92699883..2bdedecaa 100644
--- a/packages/babel-parser/src/util/scopeflags.js
Expand Down Expand Up @@ -338,19 +196,6 @@ index 1b534b8fc..000000000
-import runner from "@babel/helper-plugin-test-runner";
-
-runner(__dirname);
diff --git a/packages/babel-register/src/cache.js b/packages/babel-register/src/cache.js
index b505bb494..804bdb19b 100644
--- a/packages/babel-register/src/cache.js
+++ b/packages/babel-register/src/cache.js
@@ -17,7 +17,7 @@ let data: Object = {};
let cacheDisabled = false;

function isCacheDisabled() {
- return process.env.BABEL_DISABLE_CACHE ?? cacheDisabled;
+ return process.env.BABEL_DISABLE_CACHE != null ? process.env.BABEL_DISABLE_CACHE : cacheDisabled;
}
/**
* Write stringified cache to disk.
diff --git a/scripts/gulp-tasks.js b/scripts/gulp-tasks.js
index 73c1f7db2..59c35bfcf 100644
--- a/scripts/gulp-tasks.js
Expand Down

0 comments on commit ed3995f

Please sign in to comment.