diff --git a/.gitignore b/.gitignore index abad1f9..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ node_modules -test.js -test.css diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 4a3c398..0000000 --- a/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -support -test -examples -*.sock -test.css -test.js diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 09d3ef3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: node_js -node_js: - - 0.8 - - 0.10 diff --git a/History.md b/History.md index a5d09ae..4a93ca7 100644 --- a/History.md +++ b/History.md @@ -1,28 +1,78 @@ +2.0.0 / 2014-06-18 +================== + + * update 'css' to 2.0.0 + * depend on the 'css' package, which now contains the parser + +1.7.0 / 2013-12-21 +================== + + * allow # in property names + * report filename in errors if available + +1.6.0 / 2013-10-16 +================== + + * add @host support. Closes #54 + * add benchmarks + * add `source` property to `position` + * change: relax keyframe selectors and property names + +1.5.3 / 2013-09-10 +================== + + * add trim shim function. Closes #45 + * fix: parser now correctly parses attributes with whitespace before colon + +1.5.2 / 2013-07-28 +================== + + * fix another regexp for good old FF + +1.5.1 / 2013-07-23 +================== + + * fix // declaration hack. Closes #42 + * fix comments for several nodes (#34). + +1.5.0 / 2013-06-18 +================== + + * add error reporting + * fix @document with no vendor prefix + +1.4.0 / 2013-05-22 +================== + + * add `position` option support + * add .type to all nodes. Closes #18 + * fix comments within rulesets. Closes #30 + * fix handling of unterminated comment. Closes #24 -1.3.0 / 2013-05-21 +1.3.0 / 2013-05-21 ================== * add @document parsing. Closes #29 -1.2.0 / 2013-03-28 +1.2.0 / 2013-03-28 ================== * add support for @page at-rules with nested @margin at-rules. * add @namespace support. * add support for new @supports at-rule. -1.1.0 / 2013-03-18 +1.1.0 / 2013-03-18 ================== * add comment parsing -1.0.4 / 2012-09-17 +1.0.4 / 2012-09-17 ================== * fix keyframes float percentages * fix an issue with comments containing slashes. -1.0.3 / 2012-09-01 +1.0.3 / 2012-09-01 ================== * add component support @@ -30,13 +80,13 @@ * fix keyframe names with no whitespace [rstacruz] * fix excess semicolon support [rstacruz] -1.0.2 / 2012-09-01 +1.0.2 / 2012-09-01 ================== * fix IE property hack support [rstacruz] * fix quoted strings in declarations [rstacruz] -1.0.1 / 2012-07-26 +1.0.1 / 2012-07-26 ================== * change "selector" to "selectors" array diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b740930 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2013 TJ Holowaychuk + +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. diff --git a/Makefile b/Makefile deleted file mode 100644 index d78a055..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ - -test: - @./node_modules/.bin/mocha \ - --require should \ - --reporter spec \ - --bail - -.PHONY: test diff --git a/Readme.md b/Readme.md index fde74a5..99a4743 100644 --- a/Readme.md +++ b/Readme.md @@ -1,62 +1,15 @@ - # css-parse - CSS parser. - -## Example - -js: - -```js -var parse = require('css-parse') -parse('tobi { name: "tobi" }') -``` - -object returned: - -```json -{ - "stylesheet": { - "rules": [ - { - "selectors": ["tobi"], - "declarations": [ - { - "property": "name", - "value": "tobi" - } - ] - } - ] - } -} -``` - -## Performance - - Parsed 15,000 lines of CSS (2mb) in 40ms on my macbook air. + JavaScript CSS parser for Node.js (exports the `parse` method of [css](https://github.com/reworkcss/css)) -## License +## Installation -(The MIT License) + $ npm install css-parse -Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca> +## Usage -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: + Please see the [css](https://github.com/reworkcss/css) module documentation. -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +## License -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. \ No newline at end of file + MIT diff --git a/component.json b/component.json deleted file mode 100644 index 57e8cfb..0000000 --- a/component.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "css-parse", - "repo": "visionmedia/css-parse", - "version": "1.3.0", - "description": "CSS parser", - "keywords": ["css", "parser", "stylesheet"], - "scripts": ["index.js"] -} diff --git a/examples/dialog.css b/examples/dialog.css deleted file mode 100644 index df74183..0000000 --- a/examples/dialog.css +++ /dev/null @@ -1,92 +0,0 @@ -#dialog { - position: fixed; - left: 50%; - top: 150px; - max-width: 600px; - min-width: 250px; - border: 1px solid #eee; - background: white; - z-index: 1000; -} - -#dialog .content { - padding: 15px 20px; -} - -#dialog h1 { - margin: 0 0 5px 0; - font-size: 16px; - font-weight: normal; -} - -#dialog p { - margin: 0; - padding: 0; - font-size: .9em; -} - -#dialog.modal { - box-shadow: 0 1px 8px 0 black; -} - -/* close */ - -#dialog .close { - position: absolute; - top: 3px; - right: 10px; - text-decoration: none; - color: #888; - font-size: 16px; - font-weight: bold; - display: none; -} - -#dialog.closable .close { - display: block; -} - -#dialog .close:hover { - color: black; -} - -#dialog .close:active { - margin-top: 1px; -} - -/* slide */ - -#dialog.slide { - -webkit-transition: opacity 300ms, top 300ms; - -moz-transition: opacity 300ms, top 300ms; -} - -#dialog.slide.hide { - opacity: 0; - top: -500px; -} - -/* fade */ - -#dialog.fade { - -webkit-transition: opacity 300ms; - -moz-transition: opacity 300ms; -} - -#dialog.fade.hide { - opacity: 0; -} - -/* scale */ - -#dialog.scale { - -webkit-transition: -webkit-transform 300ms; - -moz-transition: -moz-transform 300ms; - -webkit-transform: scale(1); - -moz-transform: scale(1); -} - -#dialog.scale.hide { - -webkit-transform: scale(0); - -moz-transform: scale(0); -} \ No newline at end of file diff --git a/examples/dialog.js b/examples/dialog.js deleted file mode 100644 index f115a16..0000000 --- a/examples/dialog.js +++ /dev/null @@ -1,11 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/dialog.css', 'utf8'); - -console.log(JSON.stringify(parse(css), null, 2)); \ No newline at end of file diff --git a/index.js b/index.js index effc72d..32c8634 100644 --- a/index.js +++ b/index.js @@ -1,440 +1 @@ - -module.exports = function(css, options){ - options = options || {}; - - /** - * Positional. - */ - - var lineno = 1; - - function position() { - var start = { line: lineno }; - if (!options.position) return positionNoop; - return function(node){ - node.position = { - start: start, - end: { line: lineno } - }; - - return node; - } - } - - /** - * Parse stylesheet. - */ - - function stylesheet() { - return { - type: 'stylesheet', - stylesheet: { - rules: rules() - } - }; - } - - /** - * Opening brace. - */ - - function open() { - return match(/^{\s*/); - } - - /** - * Closing brace. - */ - - function close() { - return match(/^}\s*/); - } - - /** - * Parse ruleset. - */ - - function rules() { - var node; - var rules = []; - whitespace(); - comments(rules); - while (css[0] != '}' && (node = atrule() || rule())) { - rules.push(node); - comments(rules); - } - return rules; - } - - /** - * Match `re` and return captures. - */ - - function match(re) { - var m = re.exec(css); - if (!m) return; - var str = m[0]; - lineno += lines(str); - css = css.slice(str.length); - return m; - } - - /** - * Parse whitespace. - */ - - function whitespace() { - match(/^\s*/); - } - - /** - * Parse comments; - */ - - function comments(rules) { - var c; - rules = rules || []; - while (c = comment()) rules.push(c); - return rules; - } - - /** - * Parse comment. - */ - - function comment() { - var pos = position(); - if ('/' != css[0] || '*' != css[1]) return; - - var i = 2; - while (null != css[i] && ('*' != css[i] || '/' != css[i + 1])) ++i; - i += 2; - - var str = css.slice(2, i - 2); - css = css.slice(i); - whitespace(); - - lineno += lines(str); - - return pos({ - type: 'comment', - comment: str - }); - } - - /** - * Parse selector. - */ - - function selector() { - var m = match(/^([^{]+)/); - if (!m) return; - return m[0].trim().split(/\s*,\s*/); - } - - /** - * Parse declaration. - */ - - function declaration() { - var pos = position(); - - // prop - var prop = match(/^(\*?[-\w]+)\s*/); - if (!prop) return; - prop = prop[0]; - - // : - if (!match(/^:\s*/)) return; - - // val - var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)\s*/); - if (!val) return; - val = val[0].trim(); - - // ; - match(/^[;\s]*/); - - return pos({ - type: 'declaration', - property: prop, - value: val - }); - } - - /** - * Parse declarations. - */ - - function declarations() { - var decls = []; - - if (!open()) return; - comments(decls); - - // declarations - var decl; - while (decl = declaration()) { - decls.push(decl); - comments(decls); - } - - if (!close()) return; - return decls; - } - - /** - * Parse keyframe. - */ - - function keyframe() { - var m; - var vals = []; - var pos = position(); - - while (m = match(/^(from|to|\d+%|\.\d+%|\d+\.\d+%)\s*/)) { - vals.push(m[1]); - match(/^,\s*/); - } - - if (!vals.length) return; - - return pos({ - type: 'keyframe', - values: vals, - declarations: declarations() - }); - } - - /** - * Parse keyframes. - */ - - function atkeyframes() { - var pos = position(); - var m = match(/^@([-\w]+)?keyframes */); - - if (!m) return; - var vendor = m[1]; - - // identifier - var m = match(/^([-\w]+)\s*/); - if (!m) return; - var name = m[1]; - - if (!open()) return; - comments(); - - var frame; - var frames = []; - while (frame = keyframe()) { - frames.push(frame); - comments(); - } - - if (!close()) return; - - return pos({ - type: 'keyframes', - name: name, - vendor: vendor, - keyframes: frames - }); - } - - /** - * Parse supports. - */ - - function atsupports() { - var pos = position(); - var m = match(/^@supports *([^{]+)/); - - if (!m) return; - var supports = m[1].trim(); - - if (!open()) return; - comments(); - - var style = rules(); - - if (!close()) return; - - return pos({ - type: 'supports', - supports: supports, - rules: style - }); - } - - /** - * Parse media. - */ - - function atmedia() { - var pos = position(); - var m = match(/^@media *([^{]+)/); - - if (!m) return; - var media = m[1].trim(); - - if (!open()) return; - comments(); - - var style = rules(); - - if (!close()) return; - - return pos({ - type: 'media', - media: media, - rules: style - }); - } - - /** - * Parse paged media. - */ - - function atpage() { - var pos = position(); - var m = match(/^@page */); - if (!m) return; - - var sel = selector() || []; - var decls = []; - - if (!open()) return; - comments(); - - // declarations - var decl; - while (decl = declaration()) { - decls.push(decl); - comments(); - } - - if (!close()) return; - - return pos({ - type: 'page', - selectors: sel, - declarations: decls - }); - } - - /** - * Parse document. - */ - - function atdocument() { - var pos = position(); - var m = match(/^@([-\w]+)?document *([^{]+)/); - if (!m) return; - - var vendor = m[1].trim(); - var doc = m[2].trim(); - - if (!open()) return; - comments(); - - var style = rules(); - - if (!close()) return; - - return pos({ - type: 'document', - document: doc, - vendor: vendor, - rules: style - }); - } - - /** - * Parse import - */ - - function atimport() { - return _atrule('import'); - } - - /** - * Parse charset - */ - - function atcharset() { - return _atrule('charset'); - } - - /** - * Parse namespace - */ - - function atnamespace() { - return _atrule('namespace') - } - - /** - * Parse non-block at-rules - */ - - function _atrule(name) { - var pos = position(); - var m = match(new RegExp('^@' + name + ' *([^;\\n]+);\\s*')); - if (!m) return; - var ret = { type: name }; - ret[name] = m[1].trim(); - return pos(ret); - } - - /** - * Parse at rule. - */ - - function atrule() { - return atkeyframes() - || atmedia() - || atsupports() - || atimport() - || atcharset() - || atnamespace() - || atdocument() - || atpage(); - } - - /** - * Parse rule. - */ - - function rule() { - var pos = position(); - var sel = selector(); - - if (!sel) return; - comments(); - - return pos({ - type: 'rule', - selectors: sel, - declarations: declarations() - }); - } - - return stylesheet(); -}; - -/** - * Lines within `str`. - */ - -function lines(str) { - return str.split('\n').length - 1; -} - -/** - * Return `node`. - */ - -function positionNoop(node) { - return node; -} +module.exports = require('css').parse; diff --git a/package.json b/package.json index 0dc142c..b9b243f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,23 @@ { "name": "css-parse", - "version": "1.3.0", + "version": "2.0.0", "description": "CSS parser", - "keywords": ["css", "parser", "stylesheet"], + "main": "index", + "files": [ + "index.js" + ], + "dependencies": { + "css": "^2.0.0" + }, "author": "TJ Holowaychuk ", - "devDependencies": { - "mocha": "*", - "should": "*" + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/reworkcss/css-parse.git" }, - "main": "index" + "keywords": [ + "css", + "parser", + "stylesheet" + ] } diff --git a/test/cases/charset.css b/test/cases/charset.css deleted file mode 100644 index 035601c..0000000 --- a/test/cases/charset.css +++ /dev/null @@ -1,2 +0,0 @@ -@charset "UTF-8"; /* Set the encoding of the style sheet to Unicode UTF-8*/ -@charset 'iso-8859-15'; /* Set the encoding of the style sheet to Latin-9 (Western European languages, with euro sign) */ diff --git a/test/cases/charset.json b/test/cases/charset.json deleted file mode 100644 index 390fe0d..0000000 --- a/test/cases/charset.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "charset", - "charset": "\"UTF-8\"" - }, - { - "type": "comment", - "comment": " Set the encoding of the style sheet to Unicode UTF-8" - }, - { - "type": "charset", - "charset": "'iso-8859-15'" - }, - { - "type": "comment", - "comment": " Set the encoding of the style sheet to Latin-9 (Western European languages, with euro sign) " - } - ] - } -} \ No newline at end of file diff --git a/test/cases/comment.css b/test/cases/comment.css deleted file mode 100644 index 6fadbbb..0000000 --- a/test/cases/comment.css +++ /dev/null @@ -1,10 +0,0 @@ -/* 1 */ - -body { /* 2 */ - /* 3 */ - /**/foo: 'bar'; - /* 4 */ -} /* 5 */ - -/* 6 */ - diff --git a/test/cases/comment.json b/test/cases/comment.json deleted file mode 100644 index 4c1aac8..0000000 --- a/test/cases/comment.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "comment", - "comment": " 1 " - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "comment", - "comment": " 2 " - }, - { - "type": "comment", - "comment": " 3 " - }, - { - "type": "comment", - "comment": "" - }, - { - "type": "declaration", - "property": "foo", - "value": "'bar'" - }, - { - "type": "comment", - "comment": " 4 " - } - ] - }, - { - "type": "comment", - "comment": " 5 " - }, - { - "type": "comment", - "comment": " 6 " - } - ] - } -} diff --git a/test/cases/comment.url.css b/test/cases/comment.url.css deleted file mode 100644 index 6788a85..0000000 --- a/test/cases/comment.url.css +++ /dev/null @@ -1,7 +0,0 @@ -/* http://foo.com/bar/baz.html */ -/**/ - -foo { /*/*/ - /* something */ - bar: baz; /* http://foo.com/bar/baz.html */ -} diff --git a/test/cases/comment.url.json b/test/cases/comment.url.json deleted file mode 100644 index 6c169b7..0000000 --- a/test/cases/comment.url.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "comment", - "comment": " http://foo.com/bar/baz.html " - }, - { - "type": "comment", - "comment": "" - }, - { - "type": "rule", - "selectors": [ - "foo" - ], - "declarations": [ - { - "type": "comment", - "comment": "/" - }, - { - "type": "comment", - "comment": " something " - }, - { - "type": "declaration", - "property": "bar", - "value": "baz" - }, - { - "type": "comment", - "comment": " http://foo.com/bar/baz.html " - } - ] - } - ] - } -} diff --git a/test/cases/document.css b/test/cases/document.css deleted file mode 100644 index bff7f3f..0000000 --- a/test/cases/document.css +++ /dev/null @@ -1,5 +0,0 @@ -@-moz-document url-prefix() { - .ui-select .ui-btn select { - opacity:.0001 - } -} diff --git a/test/cases/document.json b/test/cases/document.json deleted file mode 100644 index f0bdd4f..0000000 --- a/test/cases/document.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "document", - "document": "url-prefix()", - "vendor": "-moz-", - "rules": [ - { - "type": "rule", - "selectors": [ - ".ui-select .ui-btn select" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": ".0001" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/empty.css b/test/cases/empty.css deleted file mode 100644 index e69de29..0000000 diff --git a/test/cases/empty.json b/test/cases/empty.json deleted file mode 100644 index 9a68693..0000000 --- a/test/cases/empty.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [] - } -} \ No newline at end of file diff --git a/test/cases/import.css b/test/cases/import.css deleted file mode 100644 index 3d9ad35..0000000 --- a/test/cases/import.css +++ /dev/null @@ -1,6 +0,0 @@ - -@import url("fineprint.css") print; -@import url("bluish.css") projection, tv; -@import 'custom.css'; -@import "common.css" screen, projection; -@import url('landscape.css') screen and (orientation:landscape); diff --git a/test/cases/import.json b/test/cases/import.json deleted file mode 100644 index 42c1bbd..0000000 --- a/test/cases/import.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "import", - "import": "url(\"fineprint.css\") print" - }, - { - "type": "import", - "import": "url(\"bluish.css\") projection, tv" - }, - { - "type": "import", - "import": "'custom.css'" - }, - { - "type": "import", - "import": "\"common.css\" screen, projection" - }, - { - "type": "import", - "import": "url('landscape.css') screen and (orientation:landscape)" - } - ] - } -} \ No newline at end of file diff --git a/test/cases/import.messed.css b/test/cases/import.messed.css deleted file mode 100644 index 6184cf6..0000000 --- a/test/cases/import.messed.css +++ /dev/null @@ -1,7 +0,0 @@ - - @import url("fineprint.css") print; - @import url("bluish.css") projection, tv; - @import 'custom.css'; - @import "common.css" screen, projection ; - - @import url('landscape.css') screen and (orientation:landscape); diff --git a/test/cases/import.messed.json b/test/cases/import.messed.json deleted file mode 100644 index 42c1bbd..0000000 --- a/test/cases/import.messed.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "import", - "import": "url(\"fineprint.css\") print" - }, - { - "type": "import", - "import": "url(\"bluish.css\") projection, tv" - }, - { - "type": "import", - "import": "'custom.css'" - }, - { - "type": "import", - "import": "\"common.css\" screen, projection" - }, - { - "type": "import", - "import": "url('landscape.css') screen and (orientation:landscape)" - } - ] - } -} \ No newline at end of file diff --git a/test/cases/invalid.css b/test/cases/invalid.css deleted file mode 100644 index cdd7a0f..0000000 --- a/test/cases/invalid.css +++ /dev/null @@ -1,3 +0,0 @@ -{ - - asdfasdfasdfasd \ No newline at end of file diff --git a/test/cases/invalid.json b/test/cases/invalid.json deleted file mode 100644 index 9a68693..0000000 --- a/test/cases/invalid.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [] - } -} \ No newline at end of file diff --git a/test/cases/keyframes.complex.css b/test/cases/keyframes.complex.css deleted file mode 100644 index 79eb689..0000000 --- a/test/cases/keyframes.complex.css +++ /dev/null @@ -1,8 +0,0 @@ -@keyframes foo { - 0% { top: 0; left: 0 } - 30.50% { top: 50px } - .68% , - 72% - , 85% { left: 50px } - 100% { top: 100px; left: 100% } -} \ No newline at end of file diff --git a/test/cases/keyframes.complex.json b/test/cases/keyframes.complex.json deleted file mode 100644 index fd6f0c1..0000000 --- a/test/cases/keyframes.complex.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "keyframes", - "name": "foo", - "keyframes": [ - { - "type": "keyframe", - "values": [ - "0%" - ], - "declarations": [ - { - "type": "declaration", - "property": "top", - "value": "0" - }, - { - "type": "declaration", - "property": "left", - "value": "0" - } - ] - }, - { - "type": "keyframe", - "values": [ - "30.50%" - ], - "declarations": [ - { - "type": "declaration", - "property": "top", - "value": "50px" - } - ] - }, - { - "type": "keyframe", - "values": [ - ".68%", - "72%", - "85%" - ], - "declarations": [ - { - "type": "declaration", - "property": "left", - "value": "50px" - } - ] - }, - { - "type": "keyframe", - "values": [ - "100%" - ], - "declarations": [ - { - "type": "declaration", - "property": "top", - "value": "100px" - }, - { - "type": "declaration", - "property": "left", - "value": "100%" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/keyframes.css b/test/cases/keyframes.css deleted file mode 100644 index d2e5ef7..0000000 --- a/test/cases/keyframes.css +++ /dev/null @@ -1,8 +0,0 @@ -@keyframes fade { - from { - opacity: 0; - } - to { - opacity: 1; - } -} \ No newline at end of file diff --git a/test/cases/keyframes.json b/test/cases/keyframes.json deleted file mode 100644 index 93d528d..0000000 --- a/test/cases/keyframes.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "keyframes", - "name": "fade", - "keyframes": [ - { - "type": "keyframe", - "values": [ - "from" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": "0" - } - ] - }, - { - "type": "keyframe", - "values": [ - "to" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": "1" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/keyframes.messed.css b/test/cases/keyframes.messed.css deleted file mode 100644 index 32f0be9..0000000 --- a/test/cases/keyframes.messed.css +++ /dev/null @@ -1,6 +0,0 @@ -@keyframes fade {from - {opacity: 0; - } -to - { - opacity: 1;}} \ No newline at end of file diff --git a/test/cases/keyframes.messed.json b/test/cases/keyframes.messed.json deleted file mode 100644 index 93d528d..0000000 --- a/test/cases/keyframes.messed.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "keyframes", - "name": "fade", - "keyframes": [ - { - "type": "keyframe", - "values": [ - "from" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": "0" - } - ] - }, - { - "type": "keyframe", - "values": [ - "to" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": "1" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/keyframes.vendor.css b/test/cases/keyframes.vendor.css deleted file mode 100644 index 54f15e1..0000000 --- a/test/cases/keyframes.vendor.css +++ /dev/null @@ -1,4 +0,0 @@ -@-webkit-keyframes fade { - from { opacity: 0 } - to { opacity: 1 } -} \ No newline at end of file diff --git a/test/cases/keyframes.vendor.json b/test/cases/keyframes.vendor.json deleted file mode 100644 index b9adfa0..0000000 --- a/test/cases/keyframes.vendor.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "keyframes", - "name": "fade", - "vendor": "-webkit-", - "keyframes": [ - { - "type": "keyframe", - "values": [ - "from" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": "0" - } - ] - }, - { - "type": "keyframe", - "values": [ - "to" - ], - "declarations": [ - { - "type": "declaration", - "property": "opacity", - "value": "1" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/media.css b/test/cases/media.css deleted file mode 100644 index faf083a..0000000 --- a/test/cases/media.css +++ /dev/null @@ -1,21 +0,0 @@ -@media screen, projection { - html { - background: #fffef0; - color: #300; - } - body { - max-width: 35em; - margin: 0 auto; - } -} - -@media print { - html { - background: #fff; - color: #000; - } - body { - padding: 1in; - border: 0.5pt solid #666; - } -} \ No newline at end of file diff --git a/test/cases/media.json b/test/cases/media.json deleted file mode 100644 index 897e626..0000000 --- a/test/cases/media.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "media", - "media": "screen, projection", - "rules": [ - { - "type": "rule", - "selectors": [ - "html" - ], - "declarations": [ - { - "type": "declaration", - "property": "background", - "value": "#fffef0" - }, - { - "type": "declaration", - "property": "color", - "value": "#300" - } - ] - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "max-width", - "value": "35em" - }, - { - "type": "declaration", - "property": "margin", - "value": "0 auto" - } - ] - } - ] - }, - { - "type": "media", - "media": "print", - "rules": [ - { - "type": "rule", - "selectors": [ - "html" - ], - "declarations": [ - { - "type": "declaration", - "property": "background", - "value": "#fff" - }, - { - "type": "declaration", - "property": "color", - "value": "#000" - } - ] - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "padding", - "value": "1in" - }, - { - "type": "declaration", - "property": "border", - "value": "0.5pt solid #666" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/media.messed.css b/test/cases/media.messed.css deleted file mode 100644 index 9b678f9..0000000 --- a/test/cases/media.messed.css +++ /dev/null @@ -1,27 +0,0 @@ -@media screen, projection{ html - - { -background: #fffef0; - color:#300; - } - body - -{ - max-width: 35em; - margin: 0 auto; - - -} - } - -@media print -{ - html { - background: #fff; - color: #000; - } - body { - padding: 1in; - border: 0.5pt solid #666; - } -} \ No newline at end of file diff --git a/test/cases/media.messed.json b/test/cases/media.messed.json deleted file mode 100644 index 897e626..0000000 --- a/test/cases/media.messed.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "media", - "media": "screen, projection", - "rules": [ - { - "type": "rule", - "selectors": [ - "html" - ], - "declarations": [ - { - "type": "declaration", - "property": "background", - "value": "#fffef0" - }, - { - "type": "declaration", - "property": "color", - "value": "#300" - } - ] - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "max-width", - "value": "35em" - }, - { - "type": "declaration", - "property": "margin", - "value": "0 auto" - } - ] - } - ] - }, - { - "type": "media", - "media": "print", - "rules": [ - { - "type": "rule", - "selectors": [ - "html" - ], - "declarations": [ - { - "type": "declaration", - "property": "background", - "value": "#fff" - }, - { - "type": "declaration", - "property": "color", - "value": "#000" - } - ] - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "padding", - "value": "1in" - }, - { - "type": "declaration", - "property": "border", - "value": "0.5pt solid #666" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/messed-up.css b/test/cases/messed-up.css deleted file mode 100644 index 96fcc4e..0000000 --- a/test/cases/messed-up.css +++ /dev/null @@ -1,15 +0,0 @@ -body { foo - : - 'bar' } - - body{foo:bar;bar:baz} - body - { - foo - : - bar - ; - bar - : - baz - } \ No newline at end of file diff --git a/test/cases/messed-up.json b/test/cases/messed-up.json deleted file mode 100644 index d49b0a9..0000000 --- a/test/cases/messed-up.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "foo\n ", - "value": "'bar'" - } - ] - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "foo", - "value": "bar" - }, - { - "type": "declaration", - "property": "bar", - "value": "baz" - } - ] - }, - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "foo\n ", - "value": "bar" - }, - { - "type": "declaration", - "property": "bar\n ", - "value": "baz" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/namespace.css b/test/cases/namespace.css deleted file mode 100644 index 6982d5e..0000000 --- a/test/cases/namespace.css +++ /dev/null @@ -1,2 +0,0 @@ -@namespace "http://www.w3.org/1999/xhtml"; -@namespace svg "http://www.w3.org/2000/svg"; \ No newline at end of file diff --git a/test/cases/namespace.json b/test/cases/namespace.json deleted file mode 100644 index 27dfa5b..0000000 --- a/test/cases/namespace.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "namespace", - "namespace": "\"http://www.w3.org/1999/xhtml\"" - }, - { - "type": "namespace", - "namespace": "svg \"http://www.w3.org/2000/svg\"" - } - ] - } -} \ No newline at end of file diff --git a/test/cases/no-semi.css b/test/cases/no-semi.css deleted file mode 100644 index 652cdf2..0000000 --- a/test/cases/no-semi.css +++ /dev/null @@ -1,5 +0,0 @@ - -tobi loki jane { - are: 'all'; - the-species: called "ferrets" -} diff --git a/test/cases/no-semi.json b/test/cases/no-semi.json deleted file mode 100644 index 777780b..0000000 --- a/test/cases/no-semi.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "rule", - "selectors": [ - "tobi loki jane" - ], - "declarations": [ - { - "type": "declaration", - "property": "are", - "value": "'all'" - }, - { - "type": "declaration", - "property": "the-species", - "value": "called \"ferrets\"" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/paged-media.css b/test/cases/paged-media.css deleted file mode 100644 index 6f734b5..0000000 --- a/test/cases/paged-media.css +++ /dev/null @@ -1,7 +0,0 @@ -@page toc, index:blank { - color: green; -} - -@page { - font-size: 16pt; -} diff --git a/test/cases/paged-media.json b/test/cases/paged-media.json deleted file mode 100644 index db9e2d2..0000000 --- a/test/cases/paged-media.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "page", - "selectors": [ - "toc", - "index:blank" - ], - "declarations": [ - { - "type": "declaration", - "property": "color", - "value": "green" - } - ] - }, - { - "type": "page", - "selectors": [], - "declarations": [ - { - "type": "declaration", - "property": "font-size", - "value": "16pt" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/props.css b/test/cases/props.css deleted file mode 100644 index 6549151..0000000 --- a/test/cases/props.css +++ /dev/null @@ -1,6 +0,0 @@ - -tobi loki jane { - are: 'all'; - the-species: called "ferrets"; - *even: 'ie crap'; -} diff --git a/test/cases/props.json b/test/cases/props.json deleted file mode 100644 index cff6ec8..0000000 --- a/test/cases/props.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "rule", - "selectors": [ - "tobi loki jane" - ], - "declarations": [ - { - "type": "declaration", - "property": "are", - "value": "'all'" - }, - { - "type": "declaration", - "property": "the-species", - "value": "called \"ferrets\"" - }, - { - "type": "declaration", - "property": "*even", - "value": "'ie crap'" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/quoted.css b/test/cases/quoted.css deleted file mode 100644 index 373340e..0000000 --- a/test/cases/quoted.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background: url('some;stuff;here') 50% 50% no-repeat; -} \ No newline at end of file diff --git a/test/cases/quoted.json b/test/cases/quoted.json deleted file mode 100644 index adc8574..0000000 --- a/test/cases/quoted.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "rule", - "selectors": [ - "body" - ], - "declarations": [ - { - "type": "declaration", - "property": "background", - "value": "url('some;stuff;here') 50% 50% no-repeat" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/rule.css b/test/cases/rule.css deleted file mode 100644 index 84f5ffd..0000000 --- a/test/cases/rule.css +++ /dev/null @@ -1,3 +0,0 @@ -foo { - bar: 'baz'; -} \ No newline at end of file diff --git a/test/cases/rule.json b/test/cases/rule.json deleted file mode 100644 index fe0840d..0000000 --- a/test/cases/rule.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "rule", - "selectors": [ - "foo" - ], - "declarations": [ - { - "type": "declaration", - "property": "bar", - "value": "'baz'" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/rules.css b/test/cases/rules.css deleted file mode 100644 index 329002e..0000000 --- a/test/cases/rules.css +++ /dev/null @@ -1,6 +0,0 @@ -tobi { - name: 'tobi'; -} -loki { - name: 'loki'; -} \ No newline at end of file diff --git a/test/cases/rules.json b/test/cases/rules.json deleted file mode 100644 index e25ec52..0000000 --- a/test/cases/rules.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "rule", - "selectors": [ - "tobi" - ], - "declarations": [ - { - "type": "declaration", - "property": "name", - "value": "'tobi'" - } - ] - }, - { - "type": "rule", - "selectors": [ - "loki" - ], - "declarations": [ - { - "type": "declaration", - "property": "name", - "value": "'loki'" - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/cases/supports.css b/test/cases/supports.css deleted file mode 100644 index 29158f7..0000000 --- a/test/cases/supports.css +++ /dev/null @@ -1,6 +0,0 @@ -@supports (display: flex) or (display: box) { - .flex { - display: box; - display: flex; - } -} \ No newline at end of file diff --git a/test/cases/supports.json b/test/cases/supports.json deleted file mode 100644 index 0cb191a..0000000 --- a/test/cases/supports.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "type": "stylesheet", - "stylesheet": { - "rules": [ - { - "type": "supports", - "supports": "(display: flex) or (display: box)", - "rules": [ - { - "type": "rule", - "selectors": [ - ".flex" - ], - "declarations": [ - { - "type": "declaration", - "property": "display", - "value": "box" - }, - { - "type": "declaration", - "property": "display", - "value": "flex" - } - ] - } - ] - } - ] - } -} \ No newline at end of file diff --git a/test/css-parse.js b/test/css-parse.js deleted file mode 100644 index ed615fc..0000000 --- a/test/css-parse.js +++ /dev/null @@ -1,24 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('..') - , fs = require('fs') - , path = require('path') - , read = fs.readFileSync - , readdir = fs.readdirSync; - -describe('parse(str)', function(){ - readdir('test/cases').forEach(function(file){ - if (~file.indexOf('json')) return; - file = path.basename(file, '.css'); - it('should parse ' + file, function(){ - var css = read(path.join('test', 'cases', file + '.css'), 'utf8').trim(); - var json = read(path.join('test', 'cases', file + '.json'), 'utf8').trim(); - var ret = parse(css); - ret = JSON.stringify(ret, null, 2); - ret.should.equal(json); - }) - }); -})