prettier-plugin-eex
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -5,9 +5,15 @@ # Changelog | ||
## v.0.2.0 - 7 February 2021 | ||
## v0.3.0 - 11 February 2021 | ||
## Changes | ||
### Bug Fixes | ||
- Properly formats liveview files with form_for expressions | ||
## v0.2.0 - 7 February 2021 | ||
### Changes | ||
- decoding/encoding logic has been extracted to prettier-html-templates package | ||
## Fixed | ||
### Bug Fixes | ||
@@ -14,0 +20,0 @@ - In some cases expressions weren't decoded inside script tags |
const { tokenizeHTML } = require('prettier-html-templates'); | ||
const expressionTypeMatcher = require('./expression_type_matcher'); | ||
const { encodeFormForExpressions } = require('./liveview'); | ||
function parse(text, parsers, options) { | ||
return tokenizeHTML(text, /<%[\s\S]*?%>/gm, expressionTypeMatcher); | ||
const { liveViewFormExpressions, textWithPlaceholders } = encodeFormForExpressions(text); | ||
return { | ||
tokens: tokenizeHTML(textWithPlaceholders, /<%[\s\S]*?%>/gm, expressionTypeMatcher), | ||
liveViewFormExpressions, | ||
}; | ||
} | ||
@@ -7,0 +13,0 @@ |
@@ -5,6 +5,7 @@ const prettier = require('prettier'); | ||
const { formatEex } = require('./formatter'); | ||
const { liveViewFormForPlaceholder } = require('./liveview'); | ||
// args: path, print, textToDoc, options | ||
function embed(path, _print, textToDoc, options) { | ||
const tokens = path.stack[0]; | ||
const { tokens, liveViewFormExpressions } = path.stack[0]; | ||
@@ -18,9 +19,15 @@ const isTextWithExpressions = tokens.find((token) => token.type !== 'text'); | ||
const formattedTokens = formatEex(tokens, options); | ||
const [text, expressionMap] = encodeExpressions(formattedTokens); | ||
const [textWithPlaceholders, expressionMap] = encodeExpressions(formattedTokens); | ||
const htmlDoc = textToDoc(text, { parser: 'html' }); | ||
const htmlDoc = textToDoc(textWithPlaceholders, { parser: 'html' }); | ||
const callback = decodeExpressions(expressionMap); | ||
return mapDoc(htmlDoc, (doc) => { | ||
let newDoc = doc; | ||
if (doc === liveViewFormForPlaceholder) { | ||
newDoc = liveViewFormExpressions.shift(); | ||
} | ||
return mapDoc(htmlDoc, callback); | ||
return callback(newDoc); | ||
}); | ||
} | ||
@@ -27,0 +34,0 @@ |
{ | ||
"name": "prettier-plugin-eex", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Prettier plugin for .html.eex and .html.leex files", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1055332
11
194
2