Skip to content

Commit

Permalink
Handle shorthands in attributes correctly (#33)
Browse files Browse the repository at this point in the history
* Updates after pulling

* Add tests for handling unescaped attributes

* Add tests for attributes shorthands

* Add the possibility to handle attributes correctly

* Expect mustEscape set to `false` for boolean attributes

* Consider that boolean attributes does not nead to be escaped

* Allow throwing context-related errors for inline code

* Upgrade flow-bin

* Show errors with referencing to context

* Get rid of extra types

* Make code more clear:

Get rid of .includes method for array of 2 items

* Update react dependencies and remove temporary workaround

* Add tests for numbers as a value of attribute

* Small refactoring: rename variables and simplify the logic

* Update dependencies to get new API of pug-parser
  • Loading branch information
ezhlobo authored and ForbesLindesay committed Mar 20, 2018
1 parent 83d3350 commit 3fb864e
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 95 deletions.
6 changes: 4 additions & 2 deletions .flowconfig
Expand Up @@ -4,8 +4,10 @@
[include]

[libs]


./scripts/babel-nodes.js

[lints]

[options]

[strict]
152 changes: 87 additions & 65 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -13,10 +13,10 @@
"babylon": "6.18.0",
"common-prefix": "^1.1.0",
"pug-error": "^1.3.2",
"pug-filters": "^2.1.2",
"pug-lexer": "^3.1.0",
"pug-parser": "^4.0.0",
"pug-strip-comments": "1.0.2"
"pug-filters": "^3.0.1",
"pug-lexer": "^4.0.0",
"pug-parser": "^5.0.0",
"pug-strip-comments": "^1.0.3"
},
"devDependencies": {
"babel-cli": "^6.24.1",
Expand All @@ -25,7 +25,7 @@
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-forbeslindesay": "^2.1.0",
"babel-types": "^6.24.1",
"flow-bin": "^0.65.0",
"flow-bin": "^0.66.0",
"husky": "^0.14.3",
"jest": "^22.1.4",
"lint-staged": "^7.0.0",
Expand Down Expand Up @@ -66,4 +66,4 @@
"type": "git",
"url": "https://github.com/pugjs/babel-plugin-transform-react-pug.git"
}
}
}
25 changes: 25 additions & 0 deletions src/__tests__/__snapshots__/attributes-shorthand.test.js.snap
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JavaScript output: transformed source code 1`] = `
"// To prevent warnings in console from react
const test = 10;
module.exports = <div data-first={true} data-second={true} data-positive={true} data-negative={false} data-check={true}><div data-one={true} data-two={true} /></div>;"
`;

exports[`html output: generated html 1`] = `
<div
data-check={true}
data-first={true}
data-negative={false}
data-positive={true}
data-second={true}
>
<div
data-one={true}
data-two={true}
/>
</div>
`;

exports[`static html output: static html 1`] = `"<div data-first=\\"true\\" data-second=\\"true\\" data-positive=\\"true\\" data-negative=\\"false\\" data-check=\\"true\\"><div data-one=\\"true\\" data-two=\\"true\\"></div></div>"`;
13 changes: 13 additions & 0 deletions src/__tests__/attributes-shorthand.input.js
@@ -0,0 +1,13 @@
// To prevent warnings in console from react
const test = 10;

module.exports = pug`
div(
data-first
data-second
data-positive=true
data-negative=false
data-check
)
div(data-one data-two)
`;
3 changes: 3 additions & 0 deletions src/__tests__/attributes-shorthand.test.js
@@ -0,0 +1,3 @@
import testHelper from './test-helper';

testHelper(__dirname + '/attributes-shorthand.input.js');

0 comments on commit 3fb864e

Please sign in to comment.