dogma-css-parser
Advanced tools
Comparing version 0.0.1 to 0.0.2
const COMMENT_TYPE = 'comment' | ||
const PROPERTY_NODE = 'property' | ||
const SELECTOR_NODE = 'selector' | ||
const WHITESPACE_NODE = 'whitespace' | ||
@@ -125,2 +127,24 @@ | ||
}, | ||
{ | ||
inputs: [ | ||
'.foo {\ncolor: red;\n}', | ||
], | ||
options: { | ||
whitespace: false, | ||
}, | ||
tree: [ | ||
{ | ||
children: [ | ||
{ | ||
between: [], | ||
key: 'color', | ||
type: PROPERTY_NODE, | ||
value: 'red', | ||
}, | ||
], | ||
selector: '.foo', | ||
type: SELECTOR_NODE, | ||
}, | ||
], | ||
}, | ||
] | ||
@@ -127,0 +151,0 @@ .forEach(({inputs, options, tree}) => { |
@@ -174,9 +174,9 @@ /******/ (function(modules) { // webpackBootstrap | ||
} else if (content[index] === '/' && content[index + 1] === '*') { | ||
var _state3 = parseCommentNode(content, index, options); | ||
if (options.comments) nodes.push(_state3.node); | ||
index = _state3.index; | ||
var _state4 = parseCommentNode(content, index, options); | ||
if (options.comments) nodes.push(_state4.node); | ||
index = _state4.index; | ||
} else { | ||
var _state4 = parseSelectorNode(content, index, options); | ||
nodes.push(_state4.node); | ||
index = _state4.index; | ||
var _state5 = parseSelectorNode(content, index, options); | ||
nodes.push(_state5.node); | ||
index = _state5.index; | ||
} | ||
@@ -196,4 +196,10 @@ } | ||
while (content[end] !== '*' || content[end + 1] !== '/') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing comment'); | ||
} | ||
++end; | ||
}return { | ||
} | ||
return { | ||
index: end + 2, | ||
@@ -210,19 +216,51 @@ node: { | ||
while (end !== ':') { | ||
while (content[end] !== ':') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing property'); | ||
} | ||
++end; | ||
}var key = content.slice(start, end - 1); | ||
} | ||
var key = content.slice(start, end); | ||
// Skip ":" | ||
++end; | ||
var between = []; | ||
while (WHITESPACE.test(content[end]) || content[end] === '/' && content[end + 1] === '*') { | ||
if (WHITESPACE.test(content[end])) { | ||
var state = parseWhitespaceNode(content, end, options); | ||
if (options.whitespace) { | ||
between.push(state.node); | ||
} | ||
end = state.index; | ||
} else { | ||
var _state = parseCommentNode(content, end, options); | ||
if (options.comments) { | ||
between.push(_state.node); | ||
} | ||
end = _state.index; | ||
} | ||
} | ||
var valueStart = end; | ||
// TODO: parse comments and whitespace between nodes here | ||
while (content[end] !== ';') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing property'); | ||
} | ||
while (end !== ';') { | ||
++end; | ||
}return { | ||
index: end + 1, // Skipping to character past ";" | ||
} | ||
return { | ||
index: ++end, // Skipping to character past ";" | ||
node: { | ||
between: [], | ||
between: between, | ||
key: key, | ||
@@ -239,8 +277,18 @@ type: _types.p, | ||
while (content[end] !== '{') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing selector'); | ||
} | ||
++end; | ||
}var children = []; | ||
var selector = content.slice(start, end - 1); | ||
} | ||
var children = []; | ||
var selector = content.slice(start, end); | ||
++end; // Skip "{" | ||
while (content[end] !== '}') { | ||
if (WHITESPACE.test(content[end])) { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing selector'); | ||
} else if (WHITESPACE.test(content[end])) { | ||
var state = parseWhitespaceNode(content, end, options); | ||
@@ -250,9 +298,9 @@ if (options.whitespace) children.push(state.node); | ||
} else if (content[end] === '/' && content[end + 1] === '*') { | ||
var _state = parseCommentNode(content, end, options); | ||
if (options.comments) children.push(_state.node); | ||
end = _state.index; | ||
var _state2 = parseCommentNode(content, end, options); | ||
if (options.comments) children.push(_state2.node); | ||
end = _state2.index; | ||
} else { | ||
var _state2 = parsePropertyNode(content, end, options); | ||
children.push(_state2.node); | ||
end = _state2.index; | ||
var _state3 = parsePropertyNode(content, end, options); | ||
children.push(_state3.node); | ||
end = _state3.index; | ||
} | ||
@@ -262,6 +310,6 @@ } | ||
return { | ||
index: end, | ||
index: ++end, // Skipping to character past "}" | ||
node: { | ||
children: children, | ||
selector: selector, | ||
selector: options.whitespace ? selector : selector.trim(), | ||
type: _types.s | ||
@@ -268,0 +316,0 @@ } |
{ | ||
"name": "dogma-css-parser", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "CSS parser and compiler", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -29,4 +29,10 @@ /** | ||
while (content[end] !== '*' || content[end + 1] !== '/') ++end | ||
while (content[end] !== '*' || content[end + 1] !== '/') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing comment') | ||
} | ||
++end | ||
} | ||
return { | ||
@@ -48,19 +54,54 @@ index: end + 2, | ||
while (end !== ':') ++end | ||
while (content[end] !== ':') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing property') | ||
} | ||
const key = content.slice(start, end - 1) | ||
++end | ||
} | ||
const key = content.slice(start, end) | ||
// Skip ":" | ||
++end | ||
const between = [] | ||
while ( | ||
WHITESPACE.test(content[end]) || | ||
(content[end] === '/' && content[end + 1] === '*') | ||
) { | ||
if (WHITESPACE.test(content[end])) { | ||
const state = parseWhitespaceNode(content, end, options) | ||
if (options.whitespace) { | ||
between.push(state.node) | ||
} | ||
end = state.index | ||
} else { | ||
const state = parseCommentNode(content, end, options) | ||
if (options.comments) { | ||
between.push(state.node) | ||
} | ||
end = state.index | ||
} | ||
} | ||
const valueStart = end | ||
// TODO: parse comments and whitespace between nodes here | ||
while (content[end] !== ';') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing property') | ||
} | ||
while (end !== ';') ++end | ||
++end | ||
} | ||
return { | ||
index: end + 1, // Skipping to character past ";" | ||
index: ++end, // Skipping to character past ";" | ||
node: { | ||
between: [], | ||
between, | ||
key, | ||
@@ -80,9 +121,19 @@ type: PROPERTY_TYPE, | ||
while (content[end] !== '{') ++end | ||
while (content[end] !== '{') { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing selector') | ||
} | ||
++end | ||
} | ||
const children = [] | ||
const selector = content.slice(start, end - 1) | ||
const selector = content.slice(start, end) | ||
++end // Skip "{" | ||
while (content[end] !== '}') { | ||
if (WHITESPACE.test(content[end])) { | ||
if (end > content.length - 1) { | ||
throw new Error('Failed to finish parsing selector') | ||
} else if (WHITESPACE.test(content[end])) { | ||
const state = parseWhitespaceNode(content, end, options) | ||
@@ -103,6 +154,6 @@ if (options.whitespace) children.push(state.node) | ||
return { | ||
index: end, | ||
index: ++end, // Skipping to character past "}" | ||
node: { | ||
children, | ||
selector, | ||
selector: options.whitespace ? selector : selector.trim(), | ||
type: SELECTOR_TYPE, | ||
@@ -109,0 +160,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37679
859