Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
  • Loading branch information
dwicao committed Mar 14, 2018
commit 6721ce257d8a7a5a4d6d8f1a96c8d4d7693c242e
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/node_modules
/node_modules
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "css-to-react-native",
"version": "2.1.2",
"description": "Convert CSS text to a React Native stylesheet object",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"build": "babel ./src --ignore test.js --out-dir dist",
"test": "jest",
Expand Down
59 changes: 17 additions & 42 deletions src/TokenStream.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
const SYMBOL_MATCH = 'SYMBOL_MATCH'

module.exports = class TokenStream {
export default class TokenStream {
constructor(nodes, parent, ignoreToken) {
this.nodes = nodes;
this.parent = parent;
this.lastFunction = null;
this.lastValue = null;
this.index = 0
this.nodes = nodes
this.functionName = parent != null ? parent.value : null
this.lastValue = null
this.rewindIndex = -1
this.ignoreToken = ignoreToken;
}

get node() {
return this.nodes[0];
}

hasTokens() {
return this.nodes.length > 0;
return this.index <= this.nodes.length - 1
}

lookAhead() {
return new TokenStream(this.nodes.slice(1), this.parent, this.ignoreToken);
}

[SYMBOL_BASE_MATCH](...tokenDescriptors) {
const node = this.node;

[SYMBOL_MATCH](...tokenDescriptors) {
const node = this.nodes[this.index]
if (this.ignoreToken(node)) {
return node.value;
}

if (!node) return null;

for (let i = 0; i < tokenDescriptors.length; i += 1) {
const tokenDescriptor = tokenDescriptors[i];
const value = tokenDescriptor(node);
if (value !== null) return value;
}

return null;
}

[SYMBOL_MATCH](...tokenDescriptors) {
if (!this.hasTokens()) return null

const node = this.nodes[this.index]

for (let i = 0; i < tokenDescriptors.length; i += 1) {
const tokenDescriptor = tokenDescriptors[i]
const value = tokenDescriptor(node)
Expand All @@ -62,20 +40,17 @@ module.exports = class TokenStream {
}

expect(...tokenDescriptors) {
const value = this[SYMBOL_MATCH](...tokenDescriptors);

if (value !== null) return value;
return this.throw();
const value = this[SYMBOL_MATCH](...tokenDescriptors)
return value !== null ? value : this.throw()
}

matchesFunction() {
const node = this.node;
if (node.type !== 'function') return null;
const value = new TokenStream(node.nodes, node, this.ignoreToken);
this.nodes = this.nodes.slice(1);
this.lastFunction = value;
this.lastValue = null;
return value;
const node = this.nodes[this.index]
if (node.type !== 'function') return null
const value = new TokenStream(node.nodes, node, this.ignoreToken)
this.index += 1
this.lastValue = null
return value
}

expectFunction() {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.