mirror of
https://gitlab.com/nightlycommit/twing.git
synced 2025-01-18 08:46:50 +02:00
Resolve issue #555
This commit is contained in:
parent
1b3bb7d32e
commit
b1e132b2be
@ -1164,7 +1164,20 @@ export const createParser = (
|
||||
let token;
|
||||
let key: TwingBaseExpressionNode;
|
||||
|
||||
if ((token = stream.nextIf("STRING")) || (token = stream.nextIf("NAME")) || (token = stream.nextIf("NUMBER"))) {
|
||||
if (token = stream.nextIf("NAME")) {
|
||||
key = createConstantNode(token.value, token.line, token.column);
|
||||
|
||||
// {a} is a shortcut for {a:a}
|
||||
if (stream.test("PUNCTUATION", [',', '}'])) {
|
||||
elements.push({
|
||||
key,
|
||||
value: createNameNode(token.value, token.line, token.column)
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if ((token = stream.nextIf("STRING")) || (token = stream.nextIf("NUMBER"))) {
|
||||
key = createConstantNode(token.value, token.line, token.column);
|
||||
}
|
||||
else if (stream.test("PUNCTUATION", '(')) {
|
||||
|
@ -1,2 +1,3 @@
|
||||
import "./hash";
|
||||
import "./invalid-key";
|
||||
import "./with-value-only";
|
15
test/tests/integration/expressions/hash/with-value-only.ts
Normal file
15
test/tests/integration/expressions/hash/with-value-only.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {runTest} from "../../TestBase";
|
||||
|
||||
runTest({
|
||||
description: 'Hash key can be omitted if it is the same as the variable name',
|
||||
templates: {
|
||||
"index.twig": `
|
||||
{% set foo = "foo" %}
|
||||
{% set hash = { foo, bar: "bar" } %}
|
||||
{{ hash|join }}
|
||||
`
|
||||
},
|
||||
expectation: `
|
||||
foobar
|
||||
`
|
||||
});
|
Loading…
Reference in New Issue
Block a user