diff --git a/.babelrc b/.babelrc index b0b9a96..9e3d274 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,6 @@ { - "stage": 0 + "presets": [ + "es2015", + "stage-2" + ] } diff --git a/.eslintrc b/.eslintrc index db21f05..2746c02 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,13 +1,13 @@ --- -# babel support more syntax stuff than eslint for now -parser: babel-eslint - root: true extends: eslint:recommended ecmaFeatures: modules: true +parserOptions: + sourceType: module + env: es6: true browser: true @@ -16,7 +16,7 @@ env: rules: indent: [2, 2] # 2 spaces indentation max-len: [2, 80, 4] - quotes: [2, "double"] + quotes: [2, "double", {"allowTemplateLiterals": true}] semi: [2, "never"] no-multiple-empty-lines: [2, {"max": 1}] @@ -35,7 +35,7 @@ rules: computed-property-spacing: [2, "never"] space-unary-ops: [2, {"words": true, "nonwords": false}] - space-after-keywords: [2, "always"] + keyword-spacing: [2, {"before": true, "after": true}] space-before-blocks: [2, "always"] space-before-function-paren: [2, "never"] space-in-parens: [2, "never"] diff --git a/.gitignore b/.gitignore index 1521c8b..2f7b1b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ dist +node_modules +npm-debug.log diff --git a/.travis.yml b/.travis.yml index 31e6113..10e9429 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,5 @@ sudo: false language: node_js +node_js: + - "6" + - "4" diff --git a/package.json b/package.json index ef7b502..ccf29b7 100644 --- a/package.json +++ b/package.json @@ -20,14 +20,15 @@ "dist" ], "dependencies": { - "balanced-match": "^0.2.0", + "balanced-match": "^0.4.2", "postcss": "^5.0.0" }, "devDependencies": { - "babel": "^5.5.8", - "babel-eslint": "^3.1.15", - "babel-tape-runner": "^1.1.0", - "eslint": "^1.0.0", + "babel-cli": "^6.14.0", + "babel-preset-es2015": "^6.14.0", + "babel-preset-stage-2": "^6.13.0", + "babel-tape-runner": "^2.0.1", + "eslint": "^3.4.0", "tape": "^4.0.0" }, "scripts": { diff --git a/src/replaceRuleSelector.js b/src/replaceRuleSelector.js index b2fa725..72eec65 100644 --- a/src/replaceRuleSelector.js +++ b/src/replaceRuleSelector.js @@ -4,6 +4,21 @@ import balancedMatch from "balanced-match" const pseudoClass = ":matches" +function isElementSelector(selector) { + return !selector.match(/(\:|\.)/g) +} + +function normalizeSelector(selector, preWhitespace, pre) { + const selectorIsElement = isElementSelector(selector) + const preIsElement = isElementSelector(pre) + + if (selectorIsElement && !preIsElement) { + return `${preWhitespace}${selector}${pre}` + } + + return `${preWhitespace}${pre}${selector}` +} + function explodeSelector(selector, options) { if (selector && selector.indexOf(pseudoClass) > -1) { let newSelectors = [] @@ -33,7 +48,9 @@ function explodeSelector(selector, options) { let newParts if (postSelectors.length === 0) { - newParts = bodySelectors.map((s) => preWhitespace + pre + s) + newParts = bodySelectors.map((s) => { + return normalizeSelector(s, preWhitespace, pre) + }) } else { newParts = [] diff --git a/test/index.js b/test/index.js index d5bde5c..82e0918 100644 --- a/test/index.js +++ b/test/index.js @@ -136,5 +136,11 @@ article h3 + p {}`, "should works correctly with adjacent selectors and line break" ) + t.equal( + transform(`.foo:matches(p) {color: red;}`), + `p.foo {color: red;}`, + "should works correctly with a class and an element" + ) + t.end() })