-
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.
* Improve inline js formatting * Improve multi line attributes printing in concise mode
- Loading branch information
1 parent
622145b
commit 2336c7e
Showing
37 changed files
with
348 additions
and
171 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,65 @@ | ||
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 taglibLookup = printContext.taglibLookup; | ||
const tagName = node.tagName; | ||
|
||
if (taglibLookup && tagName) { | ||
const tagDef = taglibLookup.getTag(tagName); | ||
|
||
if (tagDef) { | ||
const featureFlags = 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; | ||
} | ||
} |
Oops, something went wrong.