-
Notifications
You must be signed in to change notification settings - Fork 6
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
0 parents
commit e1640d8
Showing
25 changed files
with
4,997 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules/ |
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 @@ | ||
nodejs 12.16.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,7 @@ | ||
Copyright 2020 Adam Zapaśnik and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,9 @@ | ||
figure out scripts and styles.. | ||
probably should use some string for that, eex1 or smth | ||
|
||
.leex | ||
|
||
attributes | ||
|
||
|
||
if <% should work to check it> |
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,23 @@ | ||
"use strict"; | ||
const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE; | ||
|
||
module.exports = { | ||
setupFiles: ["<rootDir>/tests_config/run_spec.js"], | ||
snapshotSerializers: [ | ||
"jest-snapshot-serializer-raw", | ||
// "jest-snapshot-serializer-ansi", | ||
], | ||
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", | ||
collectCoverage: ENABLE_CODE_COVERAGE, | ||
// collectCoverageFrom: ["src/**/*.js", "<rootDir>/src/**/*.js", | ||
// "!<rootDir>/node_modules/", | ||
// "!<rootDir>/tests_config/", "!<rootDir>/node_modules/"], | ||
// coveragePathIgnorePatterns: [ | ||
// "<rootDir>/standalone.js", | ||
// "<rootDir>/src/document/doc-debug.js", | ||
// "<rootDir>/src/main/massage-ast.js", | ||
// ], | ||
// coverageReporters: ["text", "lcov"], | ||
testEnvironment: "node", | ||
transform: {}, | ||
}; |
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,18 @@ | ||
{ | ||
"name": "prettier-eex", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"main": "src", | ||
"scripts": { | ||
"prettier": "prettier --plugin=. --parser=eex --print-width=120 s.eex", | ||
"html": "prettier --print-width=120 test.html", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"prettier": "^2.0.4" | ||
}, | ||
"devDependencies": { | ||
"jest": "^25.3.0", | ||
"jest-snapshot-serializer-raw": "^1.1.0" | ||
} | ||
} |
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,7 @@ | ||
<div | ||
<%= if bar13 do %> | ||
class="attribute" | ||
class="attribute" | ||
|
||
<% end %> | ||
></div> |
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 @@ | ||
const prettier = require("prettier"); | ||
const print = prettier.doc.printer.printDocToString; | ||
const { concat, group, join, line, softline } = prettier.doc.builders; |
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 @@ | ||
"use strict"; | ||
|
||
// const options = require("./options"); | ||
const parser = require("./parser"); | ||
const printers = require("./printers"); | ||
|
||
module.exports = { | ||
options: {}, | ||
defaultOptions: {}, | ||
parsers: { | ||
eex: parser, | ||
}, | ||
printers, | ||
languages: [ | ||
{ | ||
// The language name | ||
name: "Eex", | ||
// Parsers that can parse this language. | ||
// This can be built-in parsers, or parsers you have contributed via this plugin. | ||
parsers: ["eex"], | ||
extensions: [".eex", ".html.eex"], | ||
}, | ||
], | ||
}; |
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,244 @@ | ||
"use strict"; | ||
|
||
const { tokenize } = require("./tokenizer"); | ||
|
||
// const RemoteExtension = require("./extensions/custom-extension"); | ||
// const nunjucks = require("nunjucks"); | ||
// const ast = require("./ast"); | ||
|
||
// const mustache = require("mustache"); | ||
// const flatMap = require("array.prototype.flatmap"); | ||
|
||
// const env = new nunjucks.Environment(); | ||
// env.addExtension('RemoteExtension', new RemoteExtension()); | ||
|
||
// function buildPlaceholderTag(id, isAttributePlaceholder, type, nextId) { | ||
// const pid = `p${id}`; | ||
// const keepLine = type === TAG_INLINE || type === TAG_FORK; | ||
|
||
// const tagOpenStartChar = isAttributePlaceholder ? "o$" : keepLine ? "<" : "\n<"; | ||
// const tagOpenEndChar = isAttributePlaceholder ? " " : keepLine ? "/> " : ">\n"; | ||
// const tagCloseStartChar = isAttributePlaceholder ? " c$" : `\n</`; | ||
|
||
// let placeholder = ""; | ||
// let key = ""; | ||
|
||
// switch (type) { | ||
// case TAG_END: | ||
// placeholder = `${tagCloseStartChar}${pid}${tagOpenEndChar}`; | ||
// key = placeholder.trim(); | ||
// break; | ||
// case TAG_FORK: | ||
// const nextPid = `p${nextId}`; | ||
// placeholder = `${tagCloseStartChar}${pid}${tagOpenEndChar.replace( | ||
// "/", | ||
// "" | ||
// )}${tagOpenStartChar}${nextPid}${tagOpenEndChar.replace("/", "")}`; | ||
// key = `${tagCloseStartChar}${pid}${tagOpenEndChar.replace("/", "")}`.trim(); | ||
// break; | ||
// default: | ||
// placeholder = `${tagOpenStartChar}${pid}${tagOpenEndChar}`; | ||
// key = `${tagOpenStartChar}${pid}`.trim(); | ||
// } | ||
|
||
// return { | ||
// placeholder, | ||
// key, | ||
// }; | ||
// } | ||
|
||
// function buildValue(value, options) { | ||
// if (typeof value !== "string") { | ||
// return value; | ||
// } | ||
|
||
// return value | ||
// .split(" ") | ||
// .filter((x) => Boolean(x)) | ||
// .join(" "); | ||
// } | ||
|
||
// // TODO: Split out | ||
// const TAG_INLINE = 0; | ||
// const TAG_BLOCK = 1; | ||
// const TAG_END = 2; | ||
// const TAG_FORK = 3; | ||
|
||
// // TODO: Split out | ||
// const TAG_MAP = new Map([ | ||
// ["if", TAG_BLOCK], | ||
// ["for", TAG_BLOCK], | ||
// ["asyncEach", TAG_BLOCK], | ||
// ["asyncAll", TAG_BLOCK], | ||
// ["macro", TAG_BLOCK], | ||
// ["block", TAG_BLOCK], | ||
// ["raw", TAG_BLOCK], | ||
// ["verbatim", TAG_BLOCK], | ||
// ["filter", TAG_BLOCK], | ||
// ["call", TAG_BLOCK], | ||
// ["set", TAG_INLINE], | ||
// ["extends", TAG_INLINE], | ||
// ["include", TAG_INLINE], | ||
// ["import", TAG_INLINE], | ||
// ["from", TAG_INLINE], | ||
// ["else", TAG_FORK], | ||
// ["elseif", TAG_FORK], | ||
// ["elif", TAG_FORK], | ||
// ]); | ||
|
||
// function parseTag(token, tagStack, latestText, forceInline, tags = ["{%", "%}"], tagMap = new Map()) { | ||
// const { type, value, start, end } = token; | ||
|
||
// // Parsed tag | ||
// if (type === "name") { | ||
// // TODO: Solidify | ||
// const tagName = value.split(" ")[0]; | ||
|
||
// let tagType = forceInline ? TAG_INLINE : tagName.startsWith("end") ? TAG_END : tagMap.get(tagName); | ||
// if (tagType === undefined) tagType = TAG_BLOCK; | ||
|
||
// let tagId; | ||
// let nextId; | ||
|
||
// const lastTagStartChar = latestText.lastIndexOf("<"); | ||
// const lastTagEndChar = latestText.lastIndexOf(">"); | ||
// let isAttributePlaceholder = lastTagStartChar > lastTagEndChar; | ||
|
||
// if (tagType === TAG_BLOCK && tagStack.length && !forceInline) { | ||
// // Support nested tags within an element | ||
// const endStackTag = tagStack[tagStack.length - 1]; | ||
// isAttributePlaceholder = endStackTag.isAttributePlaceholder; | ||
// } | ||
|
||
// if (tagType === TAG_END || (tagType === TAG_FORK && !forceInline)) { | ||
// const offStackTag = tagStack.pop(); | ||
// tagId = offStackTag.tagId; | ||
// isAttributePlaceholder = offStackTag.isAttributePlaceholder; | ||
|
||
// if (tagType === TAG_FORK) { | ||
// nextId = placeholderId++; | ||
// } | ||
// } else { | ||
// tagId = placeholderId++; | ||
// } | ||
|
||
// const tagLength = end - start; | ||
|
||
// const { placeholder, key } = buildPlaceholderTag(tagId, isAttributePlaceholder, tagType, nextId); | ||
|
||
// token.type = "tag"; | ||
// token.tag = tagName; | ||
// token.tagId = nextId || tagId; | ||
// token.tagType = tagType; | ||
// token.placeholder = placeholder; | ||
// token.key = key; | ||
// token.isAttributePlaceholder = isAttributePlaceholder; | ||
// token.isFork = tagType === TAG_FORK; | ||
|
||
// // TODO: Rewrite value | ||
// token.print = `${tags[0]} ${buildValue(value, {})} ${tags[1]}`; // TODO: Use configured tags | ||
|
||
// if (tagType === TAG_BLOCK || tagType === TAG_FORK) { | ||
// tagStack.push(token); | ||
// } | ||
// } | ||
|
||
// return token; | ||
// } | ||
|
||
// let placeholderId = 0; | ||
|
||
// // args: text, parsers, options | ||
// function parse(text, parsers, options) { | ||
// const variableTags = ["{{", "}}"]; | ||
// // const nunjParsed = nunjucks.parser.parse(text, env.extensionsList); | ||
// // const mustacheParsed = mustache.parse(text, ["{%", "%}"]); | ||
// const variableRegex = new RegExp(variableTags[0]); | ||
|
||
// const tagMap = new Map(TAG_MAP); | ||
// options.blockTags.forEach((t) => tagMap.set(t, TAG_BLOCK)); | ||
// options.inlineTags.forEach((t) => tagMap.set(t, TAG_INLINE)); | ||
// options.forkTags.forEach((t) => tagMap.set(t, TAG_FORK)); | ||
|
||
// const tagStack = []; | ||
// let latestText = ""; | ||
|
||
// // TODO: Split out | ||
// // Handle tags | ||
// return flatMap(mustacheParsed, ([type, value, start, end]) => { | ||
// let token = { | ||
// type, | ||
// value, | ||
// start, | ||
// end, | ||
// }; | ||
|
||
// const isVariable = variableRegex.test(value); | ||
|
||
// if (type === "text") { | ||
// // Text tag, check to see if it contains the variable opening tags | ||
// if (isVariable) { | ||
// const parsed = mustache.parse(value, variableTags); | ||
// let varLatestText = latestText; | ||
|
||
// return parsed.map(([type, value, start, end]) => { | ||
// const varToken = { | ||
// type, | ||
// value, | ||
// start, | ||
// end, | ||
// }; | ||
|
||
// if (type === "text") { | ||
// varLatestText = value.trim() ? value : varLatestText; | ||
// return varToken; | ||
// } | ||
|
||
// return parseTag(varToken, tagStack, varLatestText, true, variableTags, tagMap); | ||
// }); | ||
// } else { | ||
// latestText = value.trim() ? value : latestText; | ||
// } | ||
// } else { | ||
// token = parseTag(token, tagStack, latestText, false, ["{%", "%}"], tagMap); | ||
// } | ||
|
||
// return token; | ||
// }); | ||
// } | ||
|
||
// TODO: figure this shit out | ||
function locStart(node) { | ||
// eslint-disable-next-line no-console | ||
console.log("locStart", node); | ||
return -1; | ||
} | ||
|
||
// TODO: figure this shit out | ||
|
||
function locEnd(node) { | ||
// eslint-disable-next-line no-console | ||
console.log("locEnd", node); | ||
return -1; | ||
} | ||
// TODO: figure this shit out | ||
|
||
function hasPragma(/* text */) { | ||
return false; | ||
} | ||
// function hasPragma(text) {} | ||
|
||
// function preprocess(text, options) {} | ||
function eexParse(text, parsers, options) { | ||
// console.log(tokenize(text)); | ||
return tokenize(text); | ||
} | ||
module.exports = { | ||
parse: eexParse, | ||
// The name of the AST that | ||
astFormat: "eex-ast", | ||
hasPragma, | ||
locStart, | ||
locEnd, | ||
//preprocess: preprocess | ||
}; |
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,23 @@ | ||
/** | ||
* Printer Helpers | ||
*/ | ||
|
||
"use strict"; | ||
|
||
function isBuilderLine(part) { | ||
if (typeof part !== "object") { | ||
return false; | ||
} | ||
|
||
switch (part.type) { | ||
case "line": | ||
case "break-parent": | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = { | ||
isBuilderLine, | ||
}; |
Oops, something went wrong.