From a0aa79254dec9a9cff331e90edf787106547fc70 Mon Sep 17 00:00:00 2001 From: fand Date: Sun, 28 May 2017 15:11:32 +0900 Subject: [PATCH 1/5] Add tap-spec to devDeps --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e0534fe..5515511 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "gl-shader": "^4.0.6", "glslify-deps": "^1.2.1", "standard": "^5.4.1", + "tap-spec": "^4.1.1", "tape": "^3.5.0" }, "repository": { From f35c740fa7d9372e527787c921fc7a8674cdf485 Mon Sep 17 00:00:00 2001 From: fand Date: Sun, 28 May 2017 15:15:57 +0900 Subject: [PATCH 2/5] Upgrade gl --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5515511..dd61225 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "shallow-copy": "0.0.1" }, "devDependencies": { - "gl": "^2.1.5", + "gl": "^4.0.3", "gl-shader": "^4.0.6", "glslify-deps": "^1.2.1", "standard": "^5.4.1", From c1d5d8b6746276906d4d5f3c0fa22fc82dea0bef Mon Sep 17 00:00:00 2001 From: fand Date: Sun, 28 May 2017 17:29:01 +0900 Subject: [PATCH 3/5] Install source-map --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index dd61225..a9a6dd9 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "glsl-token-whitespace-trim": "^1.0.0", "glsl-tokenizer": "^2.0.2", "murmurhash-js": "^1.0.0", - "shallow-copy": "0.0.1" + "shallow-copy": "0.0.1", + "source-map": "^0.5.6" }, "devDependencies": { "gl": "^4.0.3", From 951dc942ff8e5e90244145d3898eb1b5d3bc8b1a Mon Sep 17 00:00:00 2001 From: fand Date: Sun, 28 May 2017 22:32:56 +0900 Subject: [PATCH 4/5] Output sourcemaps on bundle --- index.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index e3f5569..54a3a36 100644 --- a/index.js +++ b/index.js @@ -7,16 +7,55 @@ var inject = require('glsl-inject-defines') var defines = require('glsl-token-defines') var descope = require('glsl-token-descope') var clean = require('./lib/clean-suffixes') -var string = require('glsl-token-string') +// var string = require('glsl-token-string') var scope = require('glsl-token-scope') var depth = require('glsl-token-depth') var topoSort = require('./lib/topo-sort') var copy = require('shallow-copy') -module.exports = function (deps) { - return inject(Bundle(deps).src, { - GLSLIFY: 1 +// Mock glsl-token-string +// as it doesn't support sourcemaps +const sourceMap = require('source-map') +const string = (tokens) => { + const output = []; + const map = new sourceMap.SourceMapGenerator(); + + let line = 1 + let column = 1 + + tokens.forEach(token => { + if (token.type === 'eof') return + + output.push(token.data) + + map.addMapping({ + source: token.source, + original: { + line: token.original.line, + column: token.original.column, + }, + generated: { + line: line, + column: column + }, + }); + + const lines = token.data.split(/\r\n|\r|\n/) + line += lines.length - 1 + column = lines.length > 1 ? + lines[lines.length - 1].length : + (column + token.data.length) }) + + console.log(map.toString()) + return output.join(''); +} + +module.exports = function (deps, opts) { + // return inject(Bundle(deps, opts).src, { + // GLSLIFY: 1 + // }) + return Bundle(deps, opts).src } function Bundle (deps) { @@ -44,7 +83,7 @@ function Bundle (deps) { } this.src = string(this.src) - this.src = string(clean(trim(tokenize(this.src)))) + // this.src = string(clean(trim(tokenize(this.src)))) } var proto = Bundle.prototype @@ -59,6 +98,14 @@ proto.preprocess = function (dep) { for (var i = 0; i < tokens.length; i++) { var token = tokens[i] + token.source = dep.file + + // Save original position + token.original = { + line: token.line, + column: Math.max(token.column - token.data.length + 1, 0) + } + if (token.type !== 'preprocessor') continue if (!glslifyPreprocessor(token.data)) continue From b503da0a9fe4549eaf8e0f55d14b174aabcddf45 Mon Sep 17 00:00:00 2001 From: fand Date: Mon, 29 May 2017 00:50:36 +0900 Subject: [PATCH 5/5] Append source maps as a comment at the end of bundled code --- index.js | 8 ++++++-- package.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 54a3a36..f273a4a 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ var copy = require('shallow-copy') // Mock glsl-token-string // as it doesn't support sourcemaps const sourceMap = require('source-map') +const convert = require('convert-source-map'); const string = (tokens) => { const output = []; const map = new sourceMap.SourceMapGenerator(); @@ -47,8 +48,11 @@ const string = (tokens) => { (column + token.data.length) }) - console.log(map.toString()) - return output.join(''); + const src = output.join('') + const mapJSON = map.toString() + const mapComment = convert.fromJSON(mapJSON).toComment() + + return src + '\n' + mapComment } module.exports = function (deps, opts) { diff --git a/package.json b/package.json index a9a6dd9..826c545 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "url": "http://hughsk.io/" }, "dependencies": { + "convert-source-map": "^1.5.0", "glsl-inject-defines": "^1.0.1", "glsl-token-defines": "^1.0.0", "glsl-token-depth": "^1.1.1",