Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit({ node }) {
const prop = node.property;
if (
!node.computed &&
t.isIdentifier(prop) &&
!t.isValidES3Identifier(prop.name)
) {
// foo.default -> foo["default"]
node.property = t.stringLiteral(prop.name);
node.computed = true;
}
},
},
// e.g. import X, * as X2 from 'X'
// Else it's probably combined with a default export. keep the tmpName and destructure it
deconstructors.push(
th.buildConstDeclaration({
NAME: specifier.local,
VALUE: t.identifier(imp.tmpName),
})
);
}
} else if (t.isImportSpecifier(specifier)) {
// e.g. import { A } from 'X'
deconstructors.push(
th.buildNamedImportDestructor({
MODULE: t.identifier(imp.tmpName),
LOCAL: specifier.local,
IMPORTED: t.stringLiteral(specifier.imported.name),
})
);
} else {
throw path.buildCodeFrameError(
`Unknown ImportDeclaration specifier type ${specifier.type}`
);
}
}
path.replaceWithMultiple(deconstructors);
if (deconstructors.length) {
// Keep the same variable name if the same module is imported on another line.
imp.locked = true;
}
return;
}
loopText = `${loopText}|${node.label.name}`;
} else {
// we shouldn't be transforming these statements because
// they don't refer to the actual loop we're scopifying
if (state.ignoreLabeless) return;
// break statements mean something different in this context
if (t.isBreakStatement(node) && state.inSwitchCase) return;
}
state.hasBreakContinue = true;
state.map[loopText] = node;
replace = t.stringLiteral(loopText);
}
if (path.isReturnStatement()) {
state.hasReturn = true;
replace = t.objectExpression([
t.objectProperty(
t.identifier("v"),
node.argument || scope.buildUndefinedNode(),
),
]);
}
if (replace) {
replace = t.returnStatement(replace);
replace[this.LOOP_IGNORE] = true;
path.skip();
ImportDeclaration(path) {
if (!t.isStringLiteral(path.node.source)) return;
const source = path.node.source.value;
if (source !== "react" && source !== "react-dom") return;
const newSpecifiers = [];
for (const specifier of path.node.specifiers) {
if (
t.isImportDefaultSpecifier(specifier) ||
t.isImportNamespaceSpecifier(specifier)
) {
this.reactNamespace.add(specifier.local.name);
path.insertBefore(
t.importDeclaration(
[t.importNamespaceSpecifier(specifier.local)],
t.stringLiteral("babel-plugin-rawact/lib/runtime/react")
)
);
}
if (t.isImportSpecifier(specifier)) {
this.directImported.set(
specifier.local.name,
specifier.imported.name
);
newSpecifiers.push(
t.importSpecifier(specifier.local, specifier.imported)
);
}
}
if (newSpecifiers.length > 0) {
path.replaceWith(
t.importDeclaration(
function getKey(node) {
if (node.computed) {
return node.key;
} else if (t.isIdentifier(node.key)) {
return t.stringLiteral(node.key.name);
} else {
return t.stringLiteral(String(node.key.value));
}
}
(old, local, store) =>
t.expressionStatement(
t.callExpression(scope.importHelper("replaceEventListener"), [
scope.root(),
node,
t.stringLiteral(event),
old,
store(createListener(local))
])
),
old =>
function addDisplayName(id, call) {
const props = call.arguments[0].properties;
let safe = true;
for (let i = 0; i < props.length; i++) {
const prop = props[i];
const key = t.toComputedKey(prop);
if (t.isLiteral(key, { value: "displayName" })) {
safe = false;
break;
}
}
if (safe) {
props.unshift(
t.objectProperty(t.identifier("displayName"), t.stringLiteral(id)),
);
}
}
MemberExpression(p: NodePath) {
if (!t.isAssignmentExpression(p.parent)) {
if (p.matchesPattern('Platform.OS')) {
p.replaceWith(t.stringLiteral(platform));
} else if (p.matchesPattern('process.env.NODE_ENV')) {
p.replaceWith(t.stringLiteral(mode));
}
}
}
};
MemberExpression(p: NodePath) {
if (!t.isAssignmentExpression(p.parent)) {
if (p.matchesPattern('Platform.OS')) {
p.replaceWith(t.stringLiteral(platform));
} else if (p.matchesPattern('process.env.NODE_ENV')) {
p.replaceWith(t.stringLiteral(mode));
}
}
}
};