@babel/types#SpreadElement TypeScript Examples
The following examples show how to use
@babel/types#SpreadElement.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: babel-polyfill.ts From nota with MIT License | 6 votes |
callExpression = (
callee: Expression,
args: Array<Expression | SpreadElement>
): CallExpression => ({
type: "CallExpression",
callee,
arguments: args,
...baseNode,
})
Example #2
Source File: translate.ts From nota with MIT License | 6 votes |
toReact = (
name: Expression,
props: ([Expression, Expression] | SpreadElement)[],
children: (Expression | SpreadElement)[]
): Expression => {
let args: (Expression | SpreadElement)[] = [
name,
t.objectExpression(props.map(p => (p instanceof Array ? t.objectProperty(p[0], p[1]) : p))),
];
return t.callExpression(createEl, args.concat(children));
}
Example #3
Source File: babel-polyfill.ts From nota with MIT License | 5 votes |
objectExpression = (
properties: Array<ObjectMethod | ObjectProperty | SpreadElement>
): ObjectExpression => ({
type: "ObjectExpression",
properties,
...baseNode,
})
Example #4
Source File: babel-polyfill.ts From nota with MIT License | 5 votes |
spreadElement = (argument: Expression): SpreadElement => ({
type: "SpreadElement",
argument,
...baseNode,
})
Example #5
Source File: babel-polyfill.ts From nota with MIT License | 5 votes |
arrayExpression = (
elements: Array<null | Expression | SpreadElement>
): ArrayExpression => ({
type: "ArrayExpression",
elements,
...baseNode,
})
Example #6
Source File: translate.ts From nota with MIT License | 5 votes |
translateTextbody(node: SyntaxNode): Expression {
assert(matches(node, terms.TextBody));
let tokens = node.getChildren(terms.TextToken);
// Remove whitespace on the last line
let last = _.last(tokens);
if (last && matches(last.firstChild!, terms.Text)) {
let s = this.text(last);
if (s.match(/^[\s]*$/)) {
tokens.pop();
}
}
// Remove leading whitespace
let lineStarts = tokens
.map((_t, i) => i)
.filter(i => {
let lineStart = i > 0 && matchesNewline(tokens[i - 1].firstChild!);
return lineStart && matches(tokens[i].firstChild!, terms.Text);
});
let minLeadingWhitespace =
lineStarts.length > 0
? lineStarts
.map(i => {
let s = this.text(tokens[i]);
return s.match(/^( )*/)![0].length;
})
.reduce((a, b) => Math.min(a, b))
: 0;
let output: Either<Expression, Array<Statement>>[] = [];
tokens.forEach((token, i) => {
if (lineStarts.includes(i)) {
let stripped = this.text(token).slice(minLeadingWhitespace);
if (stripped.length > 0) {
output.push(left(processText(stripped)));
}
} else if (matchesNewline(token.firstChild!) && (i == 0 || i == tokens.length - 1)) {
// pass
} else {
output.push(this.translateToken(token));
}
});
let array: (Expression | SpreadElement)[] = [];
let curArray = array;
output.forEach(result => {
if (isLeft(result)) {
curArray.push(result.value);
} else {
let newArray: (Expression | SpreadElement)[] = [];
let body = t.blockStatement([
...result.value,
t.returnStatement(t.arrayExpression(newArray)),
]);
let fn = t.spreadElement(t.callExpression(t.arrowFunctionExpression([], body), []));
curArray.push(fn);
curArray = newArray;
}
});
return t.arrayExpression(array);
}