本文整理匯總了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);
});