-
Notifications
You must be signed in to change notification settings - Fork 36
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
f9be2c6
commit 966a556
Showing
28 changed files
with
264 additions
and
114 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const formatJS = require("./formatJS"); | ||
const toCode = require("./toCode"); | ||
const STATEMENTS = ["for", "while", "if"]; | ||
|
||
module.exports = function(node, printContext) { | ||
let code = node.argument; | ||
|
||
if (!code) { | ||
return "()"; | ||
} | ||
|
||
code = `(${toCode(code, printContext)})`; | ||
|
||
let statement; | ||
let isParams = false; | ||
|
||
if (node.type === "HTMLAttribute") { | ||
statement = getStatementName(node.name); | ||
} else { | ||
const tagName = node.tagName; | ||
const tagDef = tagName && printContext.taglibLookup.getTag(tagName); | ||
const featureFlags = tagDef && tagDef.featureFlags; | ||
isParams = featureFlags && featureFlags.includes("params"); | ||
statement = getStatementName(tagName); | ||
} | ||
|
||
try { | ||
if (STATEMENTS.includes(statement)) { | ||
return formatJS(`${statement + code};`, printContext).slice( | ||
statement.length + 1, | ||
-1 | ||
); | ||
} | ||
|
||
if (isParams) { | ||
return formatJS(`${code}=>{}`, printContext, true).slice(0, -4); | ||
} | ||
|
||
return formatJS(`_${code}`, printContext, true).slice(1); | ||
} catch (_) { | ||
return code; | ||
} | ||
}; | ||
|
||
function getStatementName(name) { | ||
switch (name) { | ||
case "if": | ||
case "for": | ||
case "while": | ||
return name; | ||
case "else-if": | ||
case "until": | ||
return "if"; | ||
default: | ||
return; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
var toCode = require("./toCode"); | ||
var formatJS = require("./formatJS"); | ||
|
||
module.exports = function getTextValue(text, printContext) { | ||
return text.argument.type === "Literal" | ||
? text.escape | ||
? text.argument.value | ||
: text.argument.value.replace(/\\|\$!?{/g, m => "\\" + m) | ||
: `$${text.escape ? "" : "!"}{${toCode( | ||
: `$${text.escape ? "" : "!"}{${formatJS( | ||
text.argument, | ||
printContext, | ||
undefined, | ||
true | ||
)}}`; | ||
}; |
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
7 changes: 0 additions & 7 deletions
7
packages/prettyprint/test/autotest/argument-attr-empty-string/expected.marko
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
packages/prettyprint/test/autotest/argument-attr-empty-string/template.marko
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
packages/prettyprint/test/autotest/argument-attr/expected.marko
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,21 @@ | ||
<div foo()/> | ||
<div foo( | ||
{ aaaaaaaaaa: 1, bbbbbbbbbb: 2, cccccccccc: 3 }, | ||
aaaaaaaaaa, | ||
bbbbbbbbbb, | ||
cccccccccc | ||
)/> | ||
-- ${test} | ||
<div>${Hello}</div> | ||
~~~~~~~ | ||
div foo() | ||
div [ | ||
foo( | ||
{ aaaaaaaaaa: 1, bbbbbbbbbb: 2, cccccccccc: 3 }, | ||
aaaaaaaaaa, | ||
bbbbbbbbbb, | ||
cccccccccc | ||
) | ||
] | ||
-- ${test} | ||
div -- ${Hello} |
5 changes: 5 additions & 0 deletions
5
packages/prettyprint/test/autotest/argument-attr/template.marko
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,5 @@ | ||
<div foo()/> | ||
<div foo({ aaaaaaaaaa: 1, bbbbbbbbbb: 2, cccccccccc: 3 }, aaaaaaaaaa, bbbbbbbbbb, cccccccccc)/> | ||
-- ${test} | ||
|
||
<div>${Hello}</div> |
3 changes: 0 additions & 3 deletions
3
packages/prettyprint/test/autotest/argument-tag-empty-string/expected.marko
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/prettyprint/test/autotest/argument-tag-empty-string/template.marko
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
packages/prettyprint/test/autotest/argument-tag/expected.marko
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 @@ | ||
<foo()/> | ||
<foo( | ||
{ aaaaaaaaaa: 1, bbbbbbbbbb: 2, cccccccccc: 3 }, | ||
aaaaaaaaaa, | ||
bbbbbbbbbb, | ||
cccccccccc | ||
)/> | ||
~~~~~~~ | ||
foo() | ||
foo( | ||
{ aaaaaaaaaa: 1, bbbbbbbbbb: 2, cccccccccc: 3 }, | ||
aaaaaaaaaa, | ||
bbbbbbbbbb, | ||
cccccccccc | ||
) |
2 changes: 2 additions & 0 deletions
2
packages/prettyprint/test/autotest/argument-tag/template.marko
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 @@ | ||
<foo()/> | ||
<foo({ aaaaaaaaaa: 1, bbbbbbbbbb: 2, cccccccccc: 3 }, aaaaaaaaaa, bbbbbbbbbb, cccccccccc)/> |
Oops, something went wrong.