Fix PaperScript support on Node.js

Closes #470.
This commit is contained in:
Jürg Lehni 2014-05-05 20:10:29 +02:00
parent 87e72744ea
commit 74d14ecf0c

View file

@ -22,6 +22,7 @@ Base.exports.PaperScript = (function() {
scope = this; scope = this;
/*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false }); /*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false });
/*#*/ if (__options.environment == 'browser') {
// We need some browser info for dealing with source maps and code offsets // We need some browser info for dealing with source maps and code offsets
var ua = navigator.userAgent, var ua = navigator.userAgent,
match = ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*([.\d]+)(?:.*rv\:([.\d]+))?/i) || [], match = ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*([.\d]+)(?:.*rv\:([.\d]+))?/i) || [],
@ -35,6 +36,7 @@ Base.exports.PaperScript = (function() {
} }
var browser = { name: name, version: parseFloat(version) }; var browser = { name: name, version: parseFloat(version) };
browser[name] = true; browser[name] = true;
/*#*/ } // __options.environment == 'browser'
// Operators to overload // Operators to overload
@ -242,6 +244,7 @@ Base.exports.PaperScript = (function() {
break; break;
} }
} }
/*#*/ if (__options.environment == 'browser') {
// Source-map support: // Source-map support:
var sourceMap = null, var sourceMap = null,
version = browser.version, version = browser.version,
@ -301,6 +304,10 @@ Base.exports.PaperScript = (function() {
JSON.stringify(sourceMap))))) JSON.stringify(sourceMap)))))
+ "\n//# sourceURL=" + (url || 'paperscript'); + "\n//# sourceURL=" + (url || 'paperscript');
} }
/*#*/ } else { // !__options.environment == 'browser'
// Now do the parsing magic
walkAST(parse(code, { ranges: true }));
/*#*/ } // !__options.environment == 'browser'
return code; return code;
} }