Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #15 from smooth-code/fix-various-bugs
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
gregberge authored Oct 5, 2018
2 parents c923005 + e8d5009 commit 1b25c34
Show file tree
Hide file tree
Showing 7 changed files with 1,734 additions and 1,437 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js

node_js:
- 6
- 8
- 10

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
"test": "jest --runInBand"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.1",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"codecov": "^3.1.0",
"eslint": "^5.6.0",
"eslint": "^5.6.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.0.1",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"jest": "^23.6.0",
"lerna": "^3.4.0",
"prettier": "^1.14.2"
"lerna": "^3.4.1",
"prettier": "^1.14.3"
},
"workspaces": [
"packages/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/h2x-parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
},
"dependencies": {
"h2x-types": "^1.1.0",
"jsdom": "^12.0.0"
"jsdom": ">=11.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/h2x-plugin-jsx/src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const formatElementOpen = jsxElement => {
const formatElementClose = jsxElement => `</${jsxElement.name}>`

const formatComment = jsxComment =>
`{/*${jsxComment.text.replace('*/', '* /')}*/}`
`{/*${jsxComment.text.replace(/\*\//g, '* /')}*/}`

const formatText = jsxText => jsxText.text
const formatText = jsxText => jsxText.text.replace(/`/g, '\\`')

export default {
JSXElement: {
Expand All @@ -44,7 +44,7 @@ export default {
JSXText: {
enter(path, generator) {
const trimmedText = path.node.text.trim()
if (trimmedText) generator.writeLine(formatText(path.node))
if (trimmedText) generator.writeLine(`{\`${formatText(path.node)}\`}`)
},
},
}
21 changes: 19 additions & 2 deletions packages/h2x-plugin-jsx/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ describe('transformJsx', () => {
<?xml version="1.0" encoding="UTF-8"?>
<svg width="88px" height="88px" viewBox="0 0 88 88" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch -->
<style>
.test {
fill: red;
}
</style>
<title>Dismiss</title>
<desc>Created with Sketch.</desc>
<defs>
Expand Down Expand Up @@ -57,11 +62,16 @@ describe('transformJsx', () => {
.toBe(`{/*?xml version="1.0" encoding="UTF-8"?*/}
<svg width="88px" height="88px" viewBox="0 0 88 88" version={1.1} xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink">
{/*Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch*/}
<style>
{\`.test {
fill: red;
}\`}
</style>
<title>
Dismiss
{\`Dismiss\`}
</title>
<desc>
Created with Sketch.
{\`Created with Sketch.\`}
</desc>
<defs>
<linearGradient id="a" x1="50%" x2="50%" y1="0%" y2="100%">
Expand Down Expand Up @@ -91,4 +101,11 @@ describe('transformJsx', () => {
`<div id="foo" style={{"fontSize":10,"lineHeight":1.2}} />`,
)
})

it('should handle special SVG attributes', () => {
const code = `<svg autoReverse="false" externalResourcesRequired="true" focusable="true" preserveAlpha="false"></svg>`
expect(transform(code, { plugins: [transformJsx] }).trim()).toBe(
'<svg autoReverse="false" externalResourcesRequired="true" focusable="true" preserveAlpha="false" />',
)
})
})
3 changes: 2 additions & 1 deletion packages/h2x-plugin-jsx/src/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { isNumeric, hyphenToCamelCase } from './util'
const ATTRIBUTE_MAPPING = {
for: 'htmlFor',
class: 'className',
autoreverse: 'autoReverse',
externalresourcesrequired: 'externalResourcesRequired',
}

const ELEMENT_ATTRIBUTE_MAPPING = {
Expand Down Expand Up @@ -155,7 +157,6 @@ export default {
HTMLElement: {
enter(path) {
const jsxElement = new JSXElement()

jsxElement.name = transformTagName(path.node.tagName)
jsxElement.attributes = listToArray(path.node.attributes)
jsxElement.children = listToArray(path.node.childNodes)
Expand Down
Loading

0 comments on commit 1b25c34

Please sign in to comment.