本文整理汇总了TypeScript中glimmer-syntax.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: astEqual
export function astEqual(actual, expected, message?) {
if (typeof actual === 'string') {
actual = parse(actual);
}
if (typeof expected === 'string') {
expected = parse(expected);
}
actual = normalizeNode(actual);
expected = normalizeNode(expected);
deepEqual(actual, expected, message);
}
示例2: test
test("html elements with nested blocks", function() {
let ast = parse(`
<div>
{{#if isSingleError}}
Single error here!
{{else if errors}}
Multiple errors here!
{{else}}
No errors found!
{{/if}} <p>Hi there!</p>
</div>
`);
let [,div] = ast.body;
let [,ifBlock,,p] = div.children;
let inverseBlock = ifBlock.inverse;
let [nestedIfBlock] = inverseBlock.body;
let nestedIfInverseBlock = nestedIfBlock.inverse;
locEqual(div, 2, 4, 10, 10, 'div element');
locEqual(ifBlock, 3, 6, 9, 13, 'outer if block');
locEqual(inverseBlock, 5, 6, 9, 6, 'inverse block');
locEqual(nestedIfBlock, 5, 6, 9, 6, 'nested if block');
locEqual(nestedIfInverseBlock, 7, 6, 9, 6, 'nested inverse block');
locEqual(p, 9, 14, 9, 30, 'p');
});
示例3: test
test("allow {{undefined}} to be passed as a param", function() {
let ast = parse("{{foo undefined}}");
astEqual(ast, b.program([
b.mustache(b.path('foo'), [b.undefined()])
]));
});
示例4: test
test('Mustaches', function() {
let ast = parse(
`{{mustache}}` +
`{{mustache param1 param2 key1=value key2=value}}`
);
traversalEqual(ast, [
['enter', ast],
['enter', ast.body[0]],
['enter', ast.body[0].path],
['exit', ast.body[0].path],
['enter', ast.body[0].hash],
['exit', ast.body[0].hash],
['exit', ast.body[0]],
['enter', ast.body[1]],
['enter', ast.body[1].path],
['exit', ast.body[1].path],
['enter', ast.body[1].params[0]],
['exit', ast.body[1].params[0]],
['enter', ast.body[1].params[1]],
['exit', ast.body[1].params[1]],
['enter', ast.body[1].hash],
['enter', ast.body[1].hash.pairs[0]],
['enter', ast.body[1].hash.pairs[0].value],
['exit', ast.body[1].hash.pairs[0].value],
['exit', ast.body[1].hash.pairs[0]],
['enter', ast.body[1].hash.pairs[1]],
['enter', ast.body[1].hash.pairs[1].value],
['exit', ast.body[1].hash.pairs[1].value],
['exit', ast.body[1].hash.pairs[1]],
['exit', ast.body[1].hash],
['exit', ast.body[1]],
['exit', ast]
]);
});
示例5: test
test('AST plugins can be chained', function() {
expect(2);
let expected = "OOOPS, MESSED THAT UP!";
function Plugin() { }
Plugin.prototype.transform = function() {
return expected;
};
function SecondaryPlugin() { }
SecondaryPlugin.prototype.transform = function(ast) {
equal(ast, expected, 'return value from AST transform is used');
return 'BOOM!';
};
let ast = parse('<div></div>', {
plugins: {
ast: [
Plugin,
SecondaryPlugin
]
}
});
equal(ast, 'BOOM!', 'return value from last AST transform is used');
});
示例6: test
test("element attribute", function() {
let ast = parse(`
<div data-foo="blah"
data-derp="lolol"
data-barf="herpy"
data-qux=lolnoquotes
data-hurky="some {{thing}} here">
Hi, fivetanley!
</div>
`);
let [,div] = ast.body;
let [dataFoo,dataDerp,dataBarf, dataQux, dataHurky] = div.attributes;
locEqual(dataFoo, 2, 9, 2, 24);
locEqual(dataDerp, 3, 6, 3, 23);
locEqual(dataBarf, 4, 0, 4, 17);
locEqual(dataQux, 5, 2, 5, 22);
locEqual(dataFoo.value, 2, 18, 2, 24);
locEqual(dataDerp.value, 3, 16, 3, 23);
locEqual(dataBarf.value, 4, 10, 4, 17);
locEqual(dataQux.value, 5, 11, 5, 22);
locEqual(dataHurky.value, 6, 15, 6, 36);
});