From 5871c2d13e068784d7ec9f8df7826fa326440929 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 10 Apr 2017 14:38:05 -0500 Subject: [PATCH] Breaking: Remove identityMap option --- lib/generate.js | 65 ------------------------------------------------- lib/helpers.js | 15 ------------ package.json | 3 --- test/add.js | 28 --------------------- 4 files changed, 111 deletions(-) delete mode 100644 lib/generate.js diff --git a/lib/generate.js b/lib/generate.js deleted file mode 100644 index 6405336..0000000 --- a/lib/generate.js +++ /dev/null @@ -1,65 +0,0 @@ -'use strict'; - -var css = require('css'); -var acorn = require('acorn'); -var SourceMapGenerator = require('source-map').SourceMapGenerator; - -function generateJs(sourcePath, fileContent) { - var generator = new SourceMapGenerator({ file: sourcePath }); - var tokenizer = acorn.tokenizer(fileContent, { locations: true }); - - while (true) { - var token = tokenizer.getToken(); - - if (token.type.label === 'eof') { - break; - } - var mapping = { - original: token.loc.start, - generated: token.loc.start, - source: sourcePath - }; - if (token.type.label === 'name') { - mapping.name = token.value; - } - generator.addMapping(mapping); - } - generator.setSourceContent(sourcePath, fileContent); - - return generator.toJSON(); -} - -function generateCss(sourcePath, fileContent) { - var generator = new SourceMapGenerator({ file: sourcePath }); - var ast = css.parse(fileContent, { silent: true }); - - function registerTokens(ast) { - if (ast.position) { - generator.addMapping({ - original: ast.position.start, - generated: ast.position.start, - source: sourcePath - }); - } - - for (var key in ast) { - if (key === 'position' || !ast[key]) { - break; - } - if (Object.prototype.toString.call(ast[key]) === '[object Object]') { - registerTokens(ast[key]); - } else if (Array.isArray(ast[key])) { - ast[key].forEach(registerTokens); - } - } - } - registerTokens(ast); - generator.setSourceContent(sourcePath, fileContent); - - return generator.toJSON(); -} - -module.exports = { - js: generateJs, - css: generateCss, -}; diff --git a/lib/helpers.js b/lib/helpers.js index 9adb79f..ac6b4ad 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -9,8 +9,6 @@ var convert = require('convert-source-map'); var stripBom = require('strip-bom'); var detectNewline = require('detect-newline'); -var generate = require('./generate'); - var urlRegex = /^(https?|webpack(-[^:]+)?):\/\//; function isRemoteSource(source) { @@ -134,19 +132,6 @@ function fixImportedSourceMap(file, state, options, callback) { function mapsLoaded(file, state, options, callback) { - if (!state.map && options.identityMap) { - var sourcePath = unixStylePath(file.relative); - - switch (file.extname) { - case '.js': - state.map = generate.js(sourcePath, state.content); - break; - case '.css': - state.map = generate.css(sourcePath, state.content); - break; - } - } - if (!state.map) { state.map = { version: 3, diff --git a/package.json b/package.json index 45e374c..4a23148 100644 --- a/package.json +++ b/package.json @@ -22,14 +22,11 @@ "vinyl-fs": "^2.4.3" }, "dependencies": { - "acorn": "^4.0.3", "async": "^2.1.4", "convert-source-map": "1.3.0", - "css": "^2.2.1", "detect-newline": "^2.1.0", "graceful-fs": "^4.1.6", "object.defaults": "^1.0.0", - "source-map": "^0.5.6", "strip-bom": "^2.0.0", "through2": "^2.0.1", "vinyl": "^1.2.0" diff --git a/test/add.js b/test/add.js index 304e6b3..aab6efa 100644 --- a/test/add.js +++ b/test/add.js @@ -165,34 +165,6 @@ describe('add', function() { }); }); - it('should add a valid source if wished', function(done) { - sourcemaps.add(makeFile(), { identityMap: true }, function(err, data) { - expect(data).toExist(); - expect(data).toExist(); - expect(data.sourceMap).toExist(); - expect(String(data.sourceMap.version)).toBe('3'); - expect(data.sourceMap.sources[0]).toBe('helloworld.js'); - expect(data.sourceMap.sourcesContent[0]).toBe(sourceContent); - expect(data.sourceMap.names).toEqual(['helloWorld', 'console','log']); - expect(data.sourceMap.mappings).toBe('AAAA,YAAY;;AAEZ,SAASA,UAAU,CAAC,EAAE;CACrBC,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;AAC5B'); - done(err); - }); - }); - - it('should add a valid source map for CSS if wished', function(done) { - sourcemaps.add(makeFileCSS(), { identityMap: true }, function(err, data) { - expect(data).toExist(); - expect(data instanceof File).toExist(); - expect(data.sourceMap).toExist(); - expect(String(data.sourceMap.version)).toBe('3'); - expect(data.sourceMap.sources[0]).toBe('test.css'); - expect(data.sourceMap.sourcesContent[0]).toBe(sourceContentCSS); - expect(data.sourceMap.names).toEqual([]); - expect(data.sourceMap.mappings).toBe('CAAC;EACC;EACA'); - done(err); - }); - }); - it('should import an existing inline source map', function(done) { sourcemaps.add(makeFileWithInlineSourceMap(), { loadMaps: true }, function(err, data) { expect(data).toExist();