Skip to content

Instantly share code, notes, and snippets.

@cspotcode
Last active February 25, 2016 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cspotcode/19a42c629944f4e074d5 to your computer and use it in GitHub Desktop.
Save cspotcode/19a42c629944f4e074d5 to your computer and use it in GitHub Desktop.
Reproduction of stylus/stylus#2125
#!/usr/bin/env bash
npm install stylus
# Dump all output into log.txt
exec > >(tee -i zlog.txt)
exec 2>&1
### Bug reproduction:
echo ====================================================================================
echo ====================================================================================
echo Using JS API, throws a useful error
node run.js proper
echo ====================================================================================
echo ====================================================================================
echo Using JS API, throws a confusing error
node run.js improper
echo ====================================================================================
echo ====================================================================================
echo Using CLI, throws a useful error
# both of these options are fine in isolation
node_modules/.bin/stylus --include-css index.styl
node_modules/.bin/stylus --resolve-url index.styl
echo ====================================================================================
echo ====================================================================================
echo Using CLI, throws a confusing error
# Used together, they cause an error
node_modules/.bin/stylus --include-css --resolve-url index.styl
"use strict";
const stylus = require('stylus');
const fs = require('fs');
switch(process.argv[2]) {
case 'proper':
// Proper error logging
stylus(fs.readFileSync('index.styl', 'utf-8'))
.set('filename', 'index.styl')
.set('include css', true)
.render(cb);
break;
case 'improper':
// Improper error logging
stylus(fs.readFileSync('index.styl', 'utf-8'))
.set('filename', 'index.styl')
.set('include css', true)
.define('url', stylus.resolver()) // I added this line which apparently breaks it.
.render(cb);
break;
default:
throw 'bad cli args';
}
function cb(err, css) {
if(err) console.log(err);
}
// One styl file includes another...
@require './other'
// ... the other styl file has an error
foo {}} // <-- a syntax error
====================================================================================
====================================================================================
Using JS API, throws a useful error
{ [ParseError: other.styl:2:8
1| // ... the other styl file has an error
2| foo {}} // <-- a syntax error
-------------^
3|
unexpected "}"
]
name: 'ParseError',
message: 'other.styl:2:8\n 1| // ... the other styl file has an error\n 2| foo {}} // <-- a syntax error\n-------------^\n 3| \n\nunexpected "}"\n',
filename: 'other.styl',
lineno: 2,
column: 8,
input: '// ... the other styl file has an error\nfoo {}} // <-- a syntax error\n' }
====================================================================================
====================================================================================
Using JS API, throws a confusing error
[TypeError: index.styl:3:1
1| // One styl file includes another...
2| @require './other'
3|
------^
Cannot read property 'nodeName' of undefined
]
====================================================================================
====================================================================================
Using CLI, throws a useful error
/Users/abradley/Desktop/stylus-error/node_modules/stylus/bin/stylus:662
throw err;
^
ParseError: other.styl:2:8
1| // ... the other styl file has an error
2| foo {}} // <-- a syntax error
-------------^
3|
unexpected "}"
at Parser.error (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:259:11)
at Parser.stmt (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:819:32)
at Parser.statement (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:685:21)
at Parser.parse (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:236:25)
at Evaluator.importFile (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:74:20)
at Evaluator.visitImport (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:906:27)
at Evaluator.Visitor.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/index.js:28:40)
at Evaluator.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:156:18)
at Evaluator.visitRoot (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:693:27)
at Evaluator.Visitor.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/index.js:28:40)
/Users/abradley/Desktop/stylus-error/node_modules/stylus/bin/stylus:662
throw err;
^
ParseError: other.styl:2:8
1| // ... the other styl file has an error
2| foo {}} // <-- a syntax error
-------------^
3|
unexpected "}"
at Parser.error (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:259:11)
at Parser.stmt (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:819:32)
at Parser.statement (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:685:21)
at Parser.parse (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/parser.js:236:25)
at Evaluator.importFile (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:74:20)
at Evaluator.visitImport (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:906:27)
at Evaluator.Visitor.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/index.js:28:40)
at Evaluator.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:156:18)
at Evaluator.visitRoot (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/evaluator.js:693:27)
at Evaluator.Visitor.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/index.js:28:40)
====================================================================================
====================================================================================
Using CLI, throws a confusing error
/Users/abradley/Desktop/stylus-error/node_modules/stylus/bin/stylus:662
throw err;
^
TypeError: index.styl:3:1
1| // One styl file includes another...
2| @require './other'
3|
------^
Cannot read property 'nodeName' of undefined
at Block.hasProperties (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/nodes/block.js:44:36)
at Normalizer.visitBlock (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/normalizer.js:212:12)
at Normalizer.Visitor.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/index.js:28:40)
at Normalizer.visitRoot (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/normalizer.js:170:23)
at Normalizer.Visitor.visit (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/index.js:28:40)
at Normalizer.normalize (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/visitor/normalizer.js:53:18)
at Renderer.render (/Users/abradley/Desktop/stylus-error/node_modules/stylus/lib/renderer.js:90:22)
at /Users/abradley/Desktop/stylus-error/node_modules/stylus/bin/stylus:656:15
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment