本文整理汇总了TypeScript中acorn.parseExpressionAt函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parseExpressionAt函数的具体用法?TypeScript parseExpressionAt怎么用?TypeScript parseExpressionAt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseExpressionAt函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: MagicString
usedHelpers.forEach(key => {
const str = shared[key];
const code = new MagicString(str);
const expression = parseExpressionAt(str, 0);
let { scope } = annotateWithScopes(expression);
walk(expression, {
enter(node: Node, parent: Node) {
if (node._scope) scope = node._scope;
if (
node.type === 'Identifier' &&
isReference(node, parent) &&
!scope.has(node.name)
) {
if (node.name in shared) {
// this helper function depends on another one
const dependency = node.name;
usedHelpers.add(dependency);
const alias = generator.alias(dependency);
if (alias !== node.name)
code.overwrite(node.start, node.end, alias);
}
}
},
leave(node: Node) {
if (node._scope) scope = scope.parent;
},
});
if (key === 'transitionManager') {
// special case
const global = `_svelteTransitionManager`;
inlineHelpers += `\n\nvar ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`;
} else {
const alias = generator.alias(expression.id.name);
if (alias !== expression.id.name)
code.overwrite(expression.id.start, expression.id.end, alias);
inlineHelpers += `\n\n${code}`;
}
});
示例2: readExpression
function readExpression(parser: Parser, start: number, quoteMark: string|null) {
let str = '';
let escaped = false;
for (let i = start; i < parser.template.length; i += 1) {
const char = parser.template[i];
if (quoteMark) {
if (char === quoteMark) {
if (escaped) {
str += quoteMark;
} else {
break;
}
} else if (escaped) {
str += '\\' + char;
escaped = false;
} else if (char === '\\') {
escaped = true;
} else {
str += char;
}
} else if (/\s/.test(char)) {
break;
} else {
str += char;
}
}
const expression = parseExpressionAt(repeat(' ', start) + str, start, {
ecmaVersion: 9,
});
parser.index = expression.end;
parser.allowWhitespace();
if (quoteMark) parser.eat(quoteMark, true);
return expression;
}
示例3: readExpression
export default function readExpression(parser: Parser) {
const start = parser.index;
const name = parser.readUntil(/\s*}}/);
if (name && /^[a-z]+$/.test(name)) {
const end = start + name.length;
if (literals.has(name)) {
return {
type: 'Literal',
start,
end,
value: literals.get(name),
raw: name,
};
}
return {
type: 'Identifier',
start,
end: start + name.length,
name,
};
}
parser.index = start;
try {
const node = parseExpressionAt(parser.template, parser.index, {
ecmaVersion: 9,
preserveParens: true,
});
parser.index = node.end;
return node;
} catch (err) {
parser.acornError(err);
}
}
示例4: readBindingDirective
export function readBindingDirective(
parser: Parser,
start: number,
name: string
) {
let value;
if (parser.eat('=')) {
const quoteMark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
const a = parser.index;
if (parser.eat('{{')) {
let message = 'bound values should not be wrapped';
const b = parser.template.indexOf('}}', a);
if (b !== -1) {
const value = parser.template.slice(parser.index, b);
message += ` â use '${value}', not '{{${value}}}'`;
}
parser.error(message, a);
}
// this is a bit of a hack so that we can give Acorn something parseable
let b;
if (quoteMark) {
b = parser.index = parser.template.indexOf(quoteMark, parser.index);
} else {
parser.readUntil(/[\s\r\n\/>]/);
b = parser.index;
}
const source = repeat(' ', a) + parser.template.slice(a, b);
value = parseExpressionAt(source, a, { ecmaVersion: 9 });
if (value.type !== 'Identifier' && value.type !== 'MemberExpression') {
parser.error(`Cannot bind to rvalue`, value.start);
}
parser.allowWhitespace();
if (quoteMark) {
parser.eat(quoteMark, true);
}
} else {
// shorthand â bind:foo equivalent to bind:foo='foo'
value = {
type: 'Identifier',
start: start + 5,
end: parser.index,
name,
};
}
return {
start,
end: parser.index,
type: 'Binding',
name,
value,
};
}