-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d94e30
commit 5383d69
Showing
47 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
let [username, age] = state.user; | ||
$lineNumber = 2; | ||
out += `${template.escape(username)}`; | ||
out += ", "; | ||
out += `${template.escape(age)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@let([username, age] = user) | ||
{{ username }}, {{ age }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"user": ["virk", 32] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
virk, 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
let [username, age, ...rest] = state.user; | ||
$lineNumber = 2; | ||
out += `${template.escape(username)}`; | ||
out += ", "; | ||
out += `${template.escape(age)}`; | ||
out += " "; | ||
out += `${template.escape(rest)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@let([username, age, ...rest] = user) | ||
{{ username }}, {{ age }} {{ rest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"user": ["virk", 32] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
virk, 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
let {username, age: userAge} = state.user; | ||
$lineNumber = 2; | ||
out += `${template.escape(username)}`; | ||
out += ", "; | ||
out += `${template.escape(userAge)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@let({ username, age: userAge } = user) | ||
{{ username }}, {{ userAge }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"user": { | ||
"username": "virk", | ||
"age": 32 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
virk, 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
let {username, age, ...rest} = state.user; | ||
$lineNumber = 2; | ||
out += `${template.escape(username)}`; | ||
out += ", "; | ||
out += `${template.escape(age)}`; | ||
out += " "; | ||
out += `${template.escape(rest)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@let({ username, age, ...rest } = user) | ||
{{ username }}, {{ age }} {{ rest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"user": { | ||
"username": "virk", | ||
"age": 32 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
virk, 32 [object Object] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
let {username, age} = state.user; | ||
$lineNumber = 2; | ||
out += `${template.escape(username)}`; | ||
out += ", "; | ||
out += `${template.escape(age)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@let({ username, age } = user) | ||
{{ username }}, {{ age }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"user": { | ||
"username": "virk", | ||
"age": 32 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
virk, 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
template.loop(state.users, function (user) { | ||
out += "\n"; | ||
$lineNumber = 2; | ||
let index = 0; | ||
$lineNumber = 3; | ||
index = index + 1; | ||
out += " "; | ||
$lineNumber = 4; | ||
out += `${template.escape(index)}`; | ||
}); | ||
$lineNumber = 6; | ||
state.index = (state.index || 0) + 1; | ||
out += ""; | ||
out += "\n"; | ||
$lineNumber = 8; | ||
out += `${template.escape(state.index)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@each(user in users) | ||
@let(index = 0) | ||
@eval(index = index + 1) | ||
{{ index }} | ||
@end | ||
@eval(index = (index || 0) + 1) | ||
|
||
{{ index }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"users": ["virk"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let out = ""; | ||
let $lineNumber = 1; | ||
let $filename = "{{__dirname}}index.edge"; | ||
try { | ||
let username = 'nikk'; | ||
$lineNumber = 2; | ||
out += `${template.escape(username)}`; | ||
} catch (error) { | ||
template.reThrow(error, $filename, $lineNumber); | ||
} | ||
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@let(username = 'nikk') | ||
{{ username }} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nikk |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"username": "virk" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* edge.js | ||
* | ||
* (c) EdgeJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { EdgeError } from 'edge-error' | ||
import { expressions } from 'edge-parser' | ||
import lodash from '@poppinss/utils/lodash' | ||
|
||
import { TagContract } from '../types.js' | ||
import { isSubsetOf, unallowedExpression, parseJsArg } from '../utils.js' | ||
|
||
/** | ||
* The let tag is used to set runtime values within the template. The value | ||
* is set inside the current scope of the template. | ||
*/ | ||
export const letTag: TagContract = { | ||
block: false, | ||
seekable: true, | ||
tagName: 'let', | ||
noNewLine: true, | ||
|
||
/** | ||
* Compiles else block node to Javascript else statement | ||
*/ | ||
compile(parser, buffer, token) { | ||
const parsed = parser.utils.generateAST( | ||
`let ${token.properties.jsArg}`, | ||
token.loc, | ||
token.filename | ||
).declarations[0] | ||
|
||
const key = parsed.id | ||
const value = parsed.init | ||
|
||
/** | ||
* The variable name has to be an identifier or the destructuring | ||
* operator. | ||
*/ | ||
isSubsetOf(key, ['ObjectPattern', expressions.Identifier, 'ArrayPattern'], () => { | ||
throw unallowedExpression( | ||
`Invalid variable name for the @let tag`, | ||
token.filename, | ||
parser.utils.getExpressionLoc(key) | ||
) | ||
}) | ||
|
||
/** | ||
* Define local variables based upon the expression | ||
*/ | ||
if (key.type === 'Identifier') { | ||
parser.stack.defineVariable(key.name) | ||
} else if (key.type === 'ObjectPattern') { | ||
key.properties.forEach((property: any) => { | ||
parser.stack.defineVariable( | ||
property.argument ? property.argument.name : property.value.name | ||
) | ||
}) | ||
} else if (key.type === 'ArrayPattern') { | ||
key.elements.forEach((element: any) => { | ||
parser.stack.defineVariable(element.argument ? element.argument.name : element.name) | ||
}) | ||
} | ||
|
||
/** | ||
* Declare let variable | ||
*/ | ||
const expression = `let ${parser.utils.stringify(key)} = ${parser.utils.stringify( | ||
parser.utils.transformAst(value, token.filename, parser) | ||
)}` | ||
|
||
buffer.writeExpression(expression, token.filename, token.loc.start.line) | ||
parser.stack.defineVariable(key.value) | ||
}, | ||
|
||
/** | ||
* Add methods to the template for running the loop | ||
*/ | ||
boot(template) { | ||
template.macro('setValue', lodash.set) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters