Files
react-native-devtools-frontend/node_modules/@babel/template/lib/formatters.js
T
Tim van der Lippe fe1b426acc Update Istanbul packages and configuration
- Update istanbul-lib-instrument (breaking change is not affecting us)
- Explicitly update @istanbuljs/schema to 0.1.3. This directly instructs
Babel to accept top-level await. As such, we can remove our special
configuration for our `ui/components/docs` folder, which we can now
safely preprocess.

DISABLE_THIRD_PARTY_CHECK=Karma fix
R=jacktfranklin@chromium.org

Bug: none
Change-Id: I0e96dce0117550f1a2db6a93654d8862d9cae95a
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3158226
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
2021-09-13 14:22:17 +00:00

71 lines
1.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.program = exports.expression = exports.statement = exports.statements = exports.smart = void 0;
var _t = require("@babel/types");
const {
assertExpressionStatement
} = _t;
function makeStatementFormatter(fn) {
return {
code: str => `/* @babel/template */;\n${str}`,
validate: () => {},
unwrap: ast => {
return fn(ast.program.body.slice(1));
}
};
}
const smart = makeStatementFormatter(body => {
if (body.length > 1) {
return body;
} else {
return body[0];
}
});
exports.smart = smart;
const statements = makeStatementFormatter(body => body);
exports.statements = statements;
const statement = makeStatementFormatter(body => {
if (body.length === 0) {
throw new Error("Found nothing to return.");
}
if (body.length > 1) {
throw new Error("Found multiple statements but wanted one");
}
return body[0];
});
exports.statement = statement;
const expression = {
code: str => `(\n${str}\n)`,
validate: ast => {
if (ast.program.body.length > 1) {
throw new Error("Found multiple statements but wanted one");
}
if (expression.unwrap(ast).start === 0) {
throw new Error("Parse result included parens.");
}
},
unwrap: ({
program
}) => {
const [stmt] = program.body;
assertExpressionStatement(stmt);
return stmt.expression;
}
};
exports.expression = expression;
const program = {
code: str => str,
validate: () => {},
unwrap: ast => ast.program
};
exports.program = program;