From 4fd77f7f4578c2d91cac2da8577bdc10612d6ece Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Mon, 29 Aug 2016 17:33:33 +0300 Subject: [PATCH 01/19] ~fix doubled files in source map Issues: https://github.com/huston007/ng-annotate-loader/issues/23 https://github.com/huston007/ng-annotate-loader/issues/24 --- loader.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/loader.js b/loader.js index 6f56da7..6a53432 100644 --- a/loader.js +++ b/loader.js @@ -43,6 +43,14 @@ function mergeSourceMaps(inputSourceMap, annotateMap) { // See also vinyl-sourcemaps-apply (used by gulp-ng-annotate) - https://github.com/floridoo/vinyl-sourcemaps-apply/blob/master/index.js if (sourceMapEnabled && inputSourceMap) { if (annotateMap) { + // it is important that sources in inputSourceMap be the same as sources in annotateMap, + // in case when using loaders (babel, tsloader, eslint) filenames in sources will be prefixed with loader executable filename. + // we should remove prefix and leave only filename + for(var i = 0; i < inputSourceMap.sources.length; i++) { + var chunks = inputSourceMap.sources[i].split('!'); + inputSourceMap.sources[i] = chunks[chunks.length - 1]; + } + var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap)); generator.applySourceMap(new SourceMapConsumer(inputSourceMap), filename); From a9822ec8e82a039ba090bafbfe9c0e58bee8808b Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Mon, 29 Aug 2016 21:25:57 +0300 Subject: [PATCH 02/19] +normalize path. Because windows doesn't care about it --- loader.js | 4 +++- package.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/loader.js b/loader.js index 6a53432..21bd3d8 100644 --- a/loader.js +++ b/loader.js @@ -2,6 +2,7 @@ var ngAnnotate = require('ng-annotate'); var utils = require('loader-utils'); var SourceMapConsumer = require('source-map').SourceMapConsumer; var SourceMapGenerator = require('source-map').SourceMapGenerator; +var normalizePath = require('normalize-path'); function loadPlugins(pluginNames) { var pluginNames = pluginNames || []; @@ -70,7 +71,8 @@ function mergeSourceMaps(inputSourceMap, annotateMap) { module.exports = function(source, inputSourceMap) { var sourceMapEnabled = this.sourceMap; - var filename = this.resourcePath; + var filename = normalizePath(this.resourcePath); + this.cacheable && this.cacheable(); var annotateResult = ngAnnotate(source, getOptions.call(this, sourceMapEnabled, filename)); diff --git a/package.json b/package.json index fced3c7..f9ebb3d 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "homepage": "https://github.com/huston007/ng-annotate-loader", "dependencies": { "ng-annotate": "1.2.1", + "normalize-path": "^2.0.1", "source-map": "0.5.4", "loader-utils": "^0.2.6" }, From 0b642b81c2749e65fa8ed364ed4b01124aa15dee Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Mon, 29 Aug 2016 21:27:46 +0300 Subject: [PATCH 03/19] ~update tests and testing environment +add new test case +update babel, webpack and update test references --- .travis.yml | 2 +- acceptance-test.sh | 11 --- {examples => cases}/babel/file-to-annotate.js | 3 +- .../babel/reference/build.js | 23 ++--- cases/babel/reference/build.js.map | 1 + {examples => cases}/babel/to-import.js | 0 {examples => cases}/babel/webpack.config.js | 9 +- .../simple/annotated-reference.js | 0 .../simple/file-to-annotate.js | 0 cases/simple/reference/build.js | 76 +++++++++++++++ cases/simple/reference/build.js.map | 1 + {examples => cases}/simple/webpack.config.js | 3 +- cases/typescript/file-to-annotate.ts | 43 +++++++++ cases/typescript/reference/build.js | 95 +++++++++++++++++++ cases/typescript/reference/build.js.map | 1 + cases/typescript/to-import.ts | 1 + cases/typescript/webpack.config.js | 41 ++++++++ examples/babel/sourcemap-reference.js.map | 1 - package.json | 23 +++-- run-tests.js | 48 ++++++++++ 20 files changed, 344 insertions(+), 38 deletions(-) delete mode 100644 acceptance-test.sh rename {examples => cases}/babel/file-to-annotate.js (85%) rename examples/babel/annotated-reference.js => cases/babel/reference/build.js (74%) create mode 100644 cases/babel/reference/build.js.map rename {examples => cases}/babel/to-import.js (100%) rename {examples => cases}/babel/webpack.config.js (71%) rename {examples => cases}/simple/annotated-reference.js (100%) rename {examples => cases}/simple/file-to-annotate.js (100%) create mode 100644 cases/simple/reference/build.js create mode 100644 cases/simple/reference/build.js.map rename {examples => cases}/simple/webpack.config.js (92%) create mode 100644 cases/typescript/file-to-annotate.ts create mode 100644 cases/typescript/reference/build.js create mode 100644 cases/typescript/reference/build.js.map create mode 100644 cases/typescript/to-import.ts create mode 100644 cases/typescript/webpack.config.js delete mode 100644 examples/babel/sourcemap-reference.js.map create mode 100644 run-tests.js diff --git a/.travis.yml b/.travis.yml index cedf0b7..feee93f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "0.12" + - "5" script: - npm test diff --git a/acceptance-test.sh b/acceptance-test.sh deleted file mode 100644 index e934dca..0000000 --- a/acceptance-test.sh +++ /dev/null @@ -1,11 +0,0 @@ - -# Simple test -npm run example-simple - -cmp examples/simple/annotated-reference.js examples/simple/dist/build.js && echo 'Simple test passed' || exit 123 - -#Babel test -npm run example-babel - -cmp examples/babel/annotated-reference.js examples/babel/dist/build.js && echo 'Babel test passed' || exit 123 -cmp examples/babel/sourcemap-reference.js.map examples/babel/dist/build.js.map && echo 'Babel sourcemap test passed' || exit 123 \ No newline at end of file diff --git a/examples/babel/file-to-annotate.js b/cases/babel/file-to-annotate.js similarity index 85% rename from examples/babel/file-to-annotate.js rename to cases/babel/file-to-annotate.js index 8603c29..f8235b3 100644 --- a/examples/babel/file-to-annotate.js +++ b/cases/babel/file-to-annotate.js @@ -24,7 +24,8 @@ angular.module('test', []) .controller('someCtrl', someCtrl); function toAnnotate($scope) { - 'ngInject'; + 'ngInject'; + console.log('hi'); // should be function body, otherwise babel remove directive prologue } class someCtrl { diff --git a/examples/babel/annotated-reference.js b/cases/babel/reference/build.js similarity index 74% rename from examples/babel/annotated-reference.js rename to cases/babel/reference/build.js index 6e3aea0..d8201e9 100644 --- a/examples/babel/annotated-reference.js +++ b/cases/babel/reference/build.js @@ -47,17 +47,17 @@ 'use strict'; toAnnotate.$inject = ["$scope"]; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _toImport = __webpack_require__(1); var _toImport2 = _interopRequireDefault(_toImport); - console.log(_toImport2['default']); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + + console.log(_toImport2.default); angular.module('test', []).controller('testCtrl', ["$scope", function ($scope) {}]).factory('testFactory', ["$cacheFactory", function ($cacheFactory) { return {}; @@ -72,9 +72,11 @@ function toAnnotate($scope) { 'ngInject'; + + console.log('hi'); // should be function body, otherwise babel remove directive prologue } - var someCtrl = (function () { + var someCtrl = function () { someCtrl.$inject = ["$scope"]; function someCtrl($scope) { _classCallCheck(this, someCtrl); @@ -88,7 +90,7 @@ }]); return someCtrl; - })(); + }(); console.log('after annotated function'); @@ -98,11 +100,10 @@ 'use strict'; - Object.defineProperty(exports, '__esModule', { + Object.defineProperty(exports, "__esModule", { value: true }); - exports['default'] = 'babel-test'; - module.exports = exports['default']; + exports.default = 'babel-test'; /***/ } /******/ ]); diff --git a/cases/babel/reference/build.js.map b/cases/babel/reference/build.js.map new file mode 100644 index 0000000..7e17646 --- /dev/null +++ b/cases/babel/reference/build.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/bootstrap b483f8263e027cd464d5","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAEhiB,KAAI,YAAY,oBAAQ;;AAExB,KAAI,aAAa,uBAAuB;;AAExC,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,SAAS;;AAEvF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAEhH,SAAQ,IAAI,WAAW;;AAEvB,SAAQ,OAAO,QAAQ,IAAI,WAAW,uBAAY,UAAU,QAAQ,KAAI,QAAQ,iCAAe,UAAU,eAAe;EACvH,OAAO;KACL,QAAQ,oBAAoB,YAAY;EAC1C,OAAO;IACL,UAAU,8BAAiB,UAAU,UAAU;EACjD,OAAO;GACN,UAAU;GACV,uBAAY,SAAS,WAAW,QAAQ;;iBAEvC,WAAW,UAAY;;AAE1B,UAAS,WAAW,QAAQ;EAC3B;;EAEA,QAAQ,IAAI;;;;gCAGc;EAC1B,SAAS,SAAS,QAAQ;GACzB,gBAAgB,MAAM;;GAEtB,KAAK;;;EAGN,aAAa,UAAU,CAAC;GACvB,KAAK;GACL,OAAO,SAAS,cAAc;;;EAG/B,OAAO;;;AAGR,SAAQ,IAAI,4B;;;;;;AC9CZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,UAAU,a","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b483f8263e027cd464d5\n **/","'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _toImport = require('./to-import');\n\nvar _toImport2 = _interopRequireDefault(_toImport);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nconsole.log(_toImport2.default);\n\nangular.module('test', []).controller('testCtrl', function ($scope) {}).factory('testFactory', function ($cacheFactory) {\n\treturn {};\n}).service('testNotAnnotated', function () {\n\treturn {};\n}).directive('testDirective', function ($timeout) {\n\treturn {\n\t\trestrict: 'E',\n\t\tcontroller: function controller($scope) {}\n\t};\n}).controller('someCtrl', someCtrl);\n\nfunction toAnnotate($scope) {\n\t'ngInject';\n\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nvar someCtrl = function () {\n\tfunction someCtrl($scope) {\n\t\t_classCallCheck(this, someCtrl);\n\n\t\tthis.doSomething();\n\t}\n\n\t_createClass(someCtrl, [{\n\t\tkey: 'doSomething',\n\t\tvalue: function doSomething() {}\n\t}]);\n\n\treturn someCtrl;\n}();\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = 'babel-test';\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/examples/babel/to-import.js b/cases/babel/to-import.js similarity index 100% rename from examples/babel/to-import.js rename to cases/babel/to-import.js diff --git a/examples/babel/webpack.config.js b/cases/babel/webpack.config.js similarity index 71% rename from examples/babel/webpack.config.js rename to cases/babel/webpack.config.js index 7c49643..daf0d10 100644 --- a/examples/babel/webpack.config.js +++ b/cases/babel/webpack.config.js @@ -5,7 +5,7 @@ var path = require('path'); module.exports = { context: __dirname, - entry: './file-to-annotate', + entry: './file-to-annotate.js', output: { path: __dirname + '/dist', filename: 'build.js' @@ -15,8 +15,11 @@ module.exports = { }, module: { loaders: [ - {test: /\.js$/, loaders: ['loader', 'babel']}, + { + test: /\.js$/, + loaders: ['loader', 'babel?presets[]=es2015'], + }, ] }, - devtool: 'source-map' + devtool: 'source-map' } diff --git a/examples/simple/annotated-reference.js b/cases/simple/annotated-reference.js similarity index 100% rename from examples/simple/annotated-reference.js rename to cases/simple/annotated-reference.js diff --git a/examples/simple/file-to-annotate.js b/cases/simple/file-to-annotate.js similarity index 100% rename from examples/simple/file-to-annotate.js rename to cases/simple/file-to-annotate.js diff --git a/cases/simple/reference/build.js b/cases/simple/reference/build.js new file mode 100644 index 0000000..56e210f --- /dev/null +++ b/cases/simple/reference/build.js @@ -0,0 +1,76 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports) { + + 'use strict'; + + namedFunction.$inject = ["$dep"]; + angular.module('test', []) + .controller('testCtrl', ["$scope", function($scope) { + + }]) + .factory('testFactory', ["$cacheFactory", function($cacheFactory) { + return {}; + }]) + .service('testNotAnnotated', function() { + return {}; + }) + .directive('testDirective', ["$timeout", function ($timeout) { + return { + restrict: 'E', + controller: ["$scope", function($scope) { + + }] + }; + }]) + .service('namedFunction', namedFunction); + + function namedFunction($dep) { + $dep.do(); + } + +/***/ } +/******/ ]); +//# sourceMappingURL=build.js.map \ No newline at end of file diff --git a/cases/simple/reference/build.js.map b/cases/simple/reference/build.js.map new file mode 100644 index 0000000..38e5d9d --- /dev/null +++ b/cases/simple/reference/build.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/bootstrap 45a88d90002041b87f37","webpack:///./file-to-annotate.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;AAEA;AACA;AACA;;AAEA,GAAE;AACF;AACA;AACA,GAAE;AACF;AACA;AACA,GAAE;AACF;AACA;AACA;AACA;;AAEA,KAAI;AACJ;AACA,GAAE;AACF;;AAEA;AACA;AACA,G","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 45a88d90002041b87f37\n **/","'use strict';\r\n\r\n\tnamedFunction.$inject = [\"$dep\"];\r\nangular.module('test', [])\r\n\t.controller('testCtrl', [\"$scope\", function($scope) {\r\n\r\n\t}])\r\n\t.factory('testFactory', [\"$cacheFactory\", function($cacheFactory) {\r\n\t\treturn {};\r\n\t}])\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', [\"$timeout\", function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: [\"$scope\", function($scope) {\r\n\r\n\t\t\t}]\r\n\t\t};\r\n\t}])\r\n\t.service('namedFunction', namedFunction);\r\n\r\n\tfunction namedFunction($dep) {\r\n\t\t$dep.do();\r\n\t}\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./file-to-annotate.js\n ** module id = 0\n ** module chunks = 0\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/examples/simple/webpack.config.js b/cases/simple/webpack.config.js similarity index 92% rename from examples/simple/webpack.config.js rename to cases/simple/webpack.config.js index 8a0ee7f..58eca57 100644 --- a/examples/simple/webpack.config.js +++ b/cases/simple/webpack.config.js @@ -14,5 +14,6 @@ module.exports = { loaders: [ {test: /\.js$/, loaders: ['loader']}, ] - } + }, + devtool: 'source-map' } \ No newline at end of file diff --git a/cases/typescript/file-to-annotate.ts b/cases/typescript/file-to-annotate.ts new file mode 100644 index 0000000..8830cbf --- /dev/null +++ b/cases/typescript/file-to-annotate.ts @@ -0,0 +1,43 @@ +'use strict'; + +declare const angular: any; + +import babelTestMsg from './to-import'; +console.log(babelTestMsg); + +angular.module('test', []) + .controller('testCtrl', function($scope) { + + }) + .factory('testFactory', function($cacheFactory) { + return {}; + }) + .service('testNotAnnotated', function() { + return {}; + }) + .directive('testDirective', function ($timeout) { + return { + restrict: 'E', + controller: function($scope) { + + } + }; + }) + .controller('someCtrl', someCtrl); + +function toAnnotate($scope) { + 'ngInject'; + console.log('hi'); // should be function body, otherwise babel remove directive prologue +} + +class someCtrl { + constructor($scope) { + this.doSomething(); + } + + doSomething() { + + } +} + +console.log('after annotated function'); \ No newline at end of file diff --git a/cases/typescript/reference/build.js b/cases/typescript/reference/build.js new file mode 100644 index 0000000..2a5e8c6 --- /dev/null +++ b/cases/typescript/reference/build.js @@ -0,0 +1,95 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + toAnnotate.$inject = ["$scope"]; + var to_import_1 = __webpack_require__(1); + console.log(to_import_1["default"]); + angular.module('test', []) + .controller('testCtrl', ["$scope", function ($scope) { + }]) + .factory('testFactory', ["$cacheFactory", function ($cacheFactory) { + return {}; + }]) + .service('testNotAnnotated', function () { + return {}; + }) + .directive('testDirective', ["$timeout", function ($timeout) { + return { + restrict: 'E', + controller: ["$scope", function ($scope) { + }] + }; + }]) + .controller('someCtrl', someCtrl); + function toAnnotate($scope) { + 'ngInject'; + console.log('hi'); // should be function body, otherwise babel remove directive prologue + } + var someCtrl = (function () { + someCtrl.$inject = ["$scope"]; + function someCtrl($scope) { + this.doSomething(); + } + someCtrl.prototype.doSomething = function () { + }; + return someCtrl; + }()); + console.log('after annotated function'); + + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + "use strict"; + exports.__esModule = true; + exports["default"] = 'babel-test'; + + +/***/ } +/******/ ]); +//# sourceMappingURL=build.js.map \ No newline at end of file diff --git a/cases/typescript/reference/build.js.map b/cases/typescript/reference/build.js.map new file mode 100644 index 0000000..47081ef --- /dev/null +++ b/cases/typescript/reference/build.js.map @@ -0,0 +1 @@ +{"version":3,"file":"build.js","sources":["webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\r\nvar to_import_1 = require('./to-import');\r\nconsole.log(to_import_1[\"default\"]);\r\nangular.module('test', [])\r\n .controller('testCtrl', function ($scope) {\r\n})\r\n .factory('testFactory', function ($cacheFactory) {\r\n return {};\r\n})\r\n .service('testNotAnnotated', function () {\r\n return {};\r\n})\r\n .directive('testDirective', function ($timeout) {\r\n return {\r\n restrict: 'E',\r\n controller: function ($scope) {\r\n }\r\n };\r\n})\r\n .controller('someCtrl', someCtrl);\r\nfunction toAnnotate($scope) {\r\n 'ngInject';\r\n console.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\nvar someCtrl = (function () {\r\n function someCtrl($scope) {\r\n this.doSomething();\r\n }\r\n someCtrl.prototype.doSomething = function () {\r\n };\r\n return someCtrl;\r\n}());\r\nconsole.log('after annotated function');\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","\"use strict\";\r\nexports.__esModule = true;\r\nexports[\"default\"] = 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACtCA;;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;AAIA;AACA;AACA;AACA;;AAEA;;AACA;AACA;;AAEA;;AAEA;;AAEA;;;;;;;AChCA;AACA;AACA;;;;","sourceRoot":""} \ No newline at end of file diff --git a/cases/typescript/to-import.ts b/cases/typescript/to-import.ts new file mode 100644 index 0000000..0475272 --- /dev/null +++ b/cases/typescript/to-import.ts @@ -0,0 +1 @@ +export default 'babel-test'; diff --git a/cases/typescript/webpack.config.js b/cases/typescript/webpack.config.js new file mode 100644 index 0000000..8faf5ee --- /dev/null +++ b/cases/typescript/webpack.config.js @@ -0,0 +1,41 @@ +// Note: this example babel and equires babel-loader +// npm install babel babel-loader + +var path = require('path'); +const DefinePlugin = require('webpack/lib/DefinePlugin'); + +module.exports = { + context: __dirname, + entry: './file-to-annotate', + output: { + path: __dirname + '/dist', + filename: 'build.js' + }, + resolveLoader: { + fallback: path.resolve(__dirname, '../../') + }, + tslint: { + configuration: { + rules: { + quotemark: [true, "double"] + } + }, + }, + resolve: { + extensions: ['.ts'], + root: __dirname, + }, + module: { + preLoaders: [ + { test: /\.ts$/, loader: 'tslint-loader', exclude: /node_modules/ }, + ], + loaders: [ + { + test: /\.ts$/, + loaders: ['loader', 'awesome-typescript-loader'], + }, + ] + }, + debug: true, + devtool: 'cheap-module-source-map' +}; diff --git a/examples/babel/sourcemap-reference.js.map b/examples/babel/sourcemap-reference.js.map deleted file mode 100644 index d806993..0000000 --- a/examples/babel/sourcemap-reference.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 26569db3c0dd06451029","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,CAAC,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAEjiB,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,WAAW;;AAEzF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAEhH,KAAI,YAAY,oBANS;;AAQzB,KAAI,aAAa,uBAAuB;;AAPxC,SAAQ,IAAG;;AAEX,SAAQ,OAAO,QAAQ,IACrB,WAAW,uBAAY,UAAS,QAAQ,KAGxC,QAAQ,iCAAe,UAAS,eAAe;EAC/C,OAAO;KAEP,QAAQ,oBAAoB,YAAW;EACvC,OAAO;IAEP,UAAU,8BAAiB,UAAU,UAAU;EAC/C,OAAO;GACN,UAAU;GACV,uBAAY,oBAAS,QAAQ;;iBAK9B,WAAW,UAAY;;AAEzB,UAAS,WAAW,QAAQ;EAC1B;;;;gCAGY;EACF,SADN,SACO,QAAQ;GACnB,gBAAgB,MAFZ;;GAEJ,KAAK;;;EAKN,aAPK,UAAQ;GAQZ,KAAK;GACL,OAJU,uBAAG;;;EAOd,OAZK;;;AAUN,SAAQ,IAAI,4B;;;;;;ACvCZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,aALO;AAMf,QAAO,UAAU,QAAQ,W","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 26569db3c0dd06451029\n **/","'use strict';\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n 'ngInject';\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/package.json b/package.json index f9ebb3d..6f0594c 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,7 @@ "description": "Webpack loader that runs ng-annotate on your bundles", "main": "loader.js", "scripts": { - "example-babel": "rm -rf examples/babel/dist && webpack --config examples/babel/webpack.config", - "example-simple": "rm -rf examples/simple/dist && webpack --config examples/simple/webpack.config", - - "acceptance-test": "bash acceptance-test.sh", - "test": "npm run acceptance-test" + "test": "node run-tests.js" }, "repository": { "type": "git", @@ -26,14 +22,23 @@ }, "homepage": "https://github.com/huston007/ng-annotate-loader", "dependencies": { + "loader-utils": "^0.2.6", "ng-annotate": "1.2.1", "normalize-path": "^2.0.1", - "source-map": "0.5.4", - "loader-utils": "^0.2.6" + "source-map": "0.5.4" }, "devDependencies": { - "babel-loader": "^5.3.2", + "awesome-typescript-loader": "^1.1.1", + "babel-core": "^6.14.0", + "babel-loader": "^6.2.5", + "babel-preset-es2015": "^6.14.0", + "crlf-helper": "^0.1.0", "node-libs-browser": "0.5.2", - "webpack": "^1.12.0" + "tap-spec": "^4.1.1", + "tape": "^4.6.0", + "tslint": "^3.15.1", + "tslint-loader": "^2.1.5", + "typescript": "^1.8.10", + "webpack": "^1.13.1" } } diff --git a/run-tests.js b/run-tests.js new file mode 100644 index 0000000..56e1400 --- /dev/null +++ b/run-tests.js @@ -0,0 +1,48 @@ +'use strict'; + +const test = require('tape'); +const webpack = require('webpack'); +const fs = require('fs'); +const crlf = require('crlf-helper'); + + +if (process.env.NODE_ENV !== 'test') { + const tapSpec = require('tap-spec'); + test.createStream() + .pipe(tapSpec()) + .pipe(process.stdout); +} + +const cases = [/*'babel', 'simple',*/ 'typescript']; + +for (let testCase of cases) { + test('Acceptance tests. Case ' + testCase, (t) => { + const folder = './cases/' + testCase; + + webpack(require(folder + '/webpack.config.js'), (err, stats) => { + if (err) { + throw err; // hard error + } + + //console[stats.hasErrors() ? 'error' : 'info'](stats.toString({ + // version: false, + // hash: false, + // assets: true, + // chunks: false, + // colors: true, + //})) + + const actualSource = fs.readFileSync(folder + '/dist/build.js', 'utf8'); + const expectedSource = fs.readFileSync(folder + '/reference/build.js', 'utf8'); + + t.equal(crlf.setLineEnding(actualSource, 'LF'), crlf.setLineEnding(expectedSource, 'LF'), 'Annotated source is valid'); + + const actualMap = fs.readFileSync(folder + '/dist/build.js.map', 'utf8'); + const expectedMap = fs.readFileSync(folder + '/reference/build.js.map', 'utf8'); + + t.equal(crlf.setLineEnding(actualMap, 'LF'), crlf.setLineEnding(expectedMap, 'LF'), 'Map is valid') + }); + + t.plan(2); + }); +} From f20c70859207c5d43c627dd33c8bab76ddc266c9 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Mon, 29 Aug 2016 22:16:06 +0300 Subject: [PATCH 04/19] +normalize path in inputSourceMap --- loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader.js b/loader.js index 21bd3d8..9fd9e10 100644 --- a/loader.js +++ b/loader.js @@ -49,7 +49,7 @@ function mergeSourceMaps(inputSourceMap, annotateMap) { // we should remove prefix and leave only filename for(var i = 0; i < inputSourceMap.sources.length; i++) { var chunks = inputSourceMap.sources[i].split('!'); - inputSourceMap.sources[i] = chunks[chunks.length - 1]; + inputSourceMap.sources[i] = normalizePath(chunks[chunks.length - 1]); } var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap)); From e0b26dece07bc936b13adbfa9ef760ac2b7ea89b Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 16:06:23 +0300 Subject: [PATCH 05/19] +editorconfig --- .editorconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0f09989 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true From 53645e2217563dfc016326695c438c50710a9f98 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 16:12:53 +0300 Subject: [PATCH 06/19] +update tet runner and reference files --- cases/babel/reference/build.js.map | 2 +- cases/simple/annotated-reference.js | 75 ------------------------- cases/simple/reference/build.js.map | 2 +- cases/typescript/reference/build.js | 4 +- cases/typescript/reference/build.js.map | 2 +- run-tests.js | 22 ++++---- 6 files changed, 17 insertions(+), 90 deletions(-) delete mode 100644 cases/simple/annotated-reference.js diff --git a/cases/babel/reference/build.js.map b/cases/babel/reference/build.js.map index 7e17646..4935cfa 100644 --- a/cases/babel/reference/build.js.map +++ b/cases/babel/reference/build.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap b483f8263e027cd464d5","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAEhiB,KAAI,YAAY,oBAAQ;;AAExB,KAAI,aAAa,uBAAuB;;AAExC,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,SAAS;;AAEvF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAEhH,SAAQ,IAAI,WAAW;;AAEvB,SAAQ,OAAO,QAAQ,IAAI,WAAW,uBAAY,UAAU,QAAQ,KAAI,QAAQ,iCAAe,UAAU,eAAe;EACvH,OAAO;KACL,QAAQ,oBAAoB,YAAY;EAC1C,OAAO;IACL,UAAU,8BAAiB,UAAU,UAAU;EACjD,OAAO;GACN,UAAU;GACV,uBAAY,SAAS,WAAW,QAAQ;;iBAEvC,WAAW,UAAY;;AAE1B,UAAS,WAAW,QAAQ;EAC3B;;EAEA,QAAQ,IAAI;;;;gCAGc;EAC1B,SAAS,SAAS,QAAQ;GACzB,gBAAgB,MAAM;;GAEtB,KAAK;;;EAGN,aAAa,UAAU,CAAC;GACvB,KAAK;GACL,OAAO,SAAS,cAAc;;;EAG/B,OAAO;;;AAGR,SAAQ,IAAI,4B;;;;;;AC9CZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,UAAU,a","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b483f8263e027cd464d5\n **/","'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _toImport = require('./to-import');\n\nvar _toImport2 = _interopRequireDefault(_toImport);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nconsole.log(_toImport2.default);\n\nangular.module('test', []).controller('testCtrl', function ($scope) {}).factory('testFactory', function ($cacheFactory) {\n\treturn {};\n}).service('testNotAnnotated', function () {\n\treturn {};\n}).directive('testDirective', function ($timeout) {\n\treturn {\n\t\trestrict: 'E',\n\t\tcontroller: function controller($scope) {}\n\t};\n}).controller('someCtrl', someCtrl);\n\nfunction toAnnotate($scope) {\n\t'ngInject';\n\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nvar someCtrl = function () {\n\tfunction someCtrl($scope) {\n\t\t_classCallCheck(this, someCtrl);\n\n\t\tthis.doSomething();\n\t}\n\n\t_createClass(someCtrl, [{\n\t\tkey: 'doSomething',\n\t\tvalue: function doSomething() {}\n\t}]);\n\n\treturn someCtrl;\n}();\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = 'babel-test';\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap b483f8263e027cd464d5","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":["console","log","angular","module","controller","$scope","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","toAnnotate","doSomething"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAAhiB;;AAIA,KAAI,aAAa,uBAAuB;;AAExC,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,SAAS;;AAEvF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAPhHA,SAAQC,IAAR;;AAEAC,SAAQC,OAAO,QAAQ,IACrBC,WAAW,uBAAY,UAASC,QAAQ,KAGxCC,QAAQ,iCAAe,UAASC,eAAe;EAC/C,OAAO;KAEPC,QAAQ,oBAAoB,YAAW;EACvC,OAAO;IAEPC,UAAU,8BAAiB,UAAUC,UAAU;EAC/C,OAAO;GACNC,UAAU;GACVP,uBAAY,oBAASC,QAAQ;;iBAK9BD,WAAW,UAAYQ;;AAEzB,UAASC,WAAWR,QAAQ;EACzB;;EACFL,QAAQC,IAAI;;;;gCAIc;EAA1B,kBAAYI,QAAQ;GAAA;;GACnB,KAAKS;;;EAMN,aAAa,UAAU,CAAC;GACvB,KAAK;GACL,OAAO,SAAS,cALH;;;EAQd,OAAO;;;AAHRd,SAAQC,IAAI,4B;;;;;;ACxCZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,UALO,a","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b483f8263e027cd464d5\n **/","'use strict';\r\n\r\nimport babelTestMsg from './to-import';\r\nconsole.log(babelTestMsg);\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.controller('someCtrl', someCtrl);\r\n \r\nfunction toAnnotate($scope) {\r\n \t'ngInject';\r\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\n\r\nclass someCtrl {\r\n\tconstructor($scope) {\r\n\t\tthis.doSomething();\r\n\t}\r\n\r\n\tdoSomething() {\r\n\r\n\t}\r\n}\r\n\r\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","export default 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/simple/annotated-reference.js b/cases/simple/annotated-reference.js deleted file mode 100644 index ffb2ddc..0000000 --- a/cases/simple/annotated-reference.js +++ /dev/null @@ -1,75 +0,0 @@ -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports) { - - 'use strict'; - - namedFunction.$inject = ["$dep"]; - angular.module('test', []) - .controller('testCtrl', ["$scope", function($scope) { - - }]) - .factory('testFactory', ["$cacheFactory", function($cacheFactory) { - return {}; - }]) - .service('testNotAnnotated', function() { - return {}; - }) - .directive('testDirective', ["$timeout", function ($timeout) { - return { - restrict: 'E', - controller: ["$scope", function($scope) { - - }] - }; - }]) - .service('namedFunction', namedFunction); - - function namedFunction($dep) { - $dep.do(); - } - -/***/ } -/******/ ]); \ No newline at end of file diff --git a/cases/simple/reference/build.js.map b/cases/simple/reference/build.js.map index 38e5d9d..dc2577b 100644 --- a/cases/simple/reference/build.js.map +++ b/cases/simple/reference/build.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 45a88d90002041b87f37","webpack:///./file-to-annotate.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;AAEA;AACA;AACA;;AAEA,GAAE;AACF;AACA;AACA,GAAE;AACF;AACA;AACA,GAAE;AACF;AACA;AACA;AACA;;AAEA,KAAI;AACJ;AACA,GAAE;AACF;;AAEA;AACA;AACA,G","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 45a88d90002041b87f37\n **/","'use strict';\r\n\r\n\tnamedFunction.$inject = [\"$dep\"];\r\nangular.module('test', [])\r\n\t.controller('testCtrl', [\"$scope\", function($scope) {\r\n\r\n\t}])\r\n\t.factory('testFactory', [\"$cacheFactory\", function($cacheFactory) {\r\n\t\treturn {};\r\n\t}])\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', [\"$timeout\", function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: [\"$scope\", function($scope) {\r\n\r\n\t\t\t}]\r\n\t\t};\r\n\t}])\r\n\t.service('namedFunction', namedFunction);\r\n\r\n\tfunction namedFunction($dep) {\r\n\t\t$dep.do();\r\n\t}\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./file-to-annotate.js\n ** module id = 0\n ** module chunks = 0\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap 45a88d90002041b87f37","webpack:///./file-to-annotate.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,SAAQ,OAAO,QAAQ;GACrB,WAAW,uBAAY,SAAS,QAAQ;;;GAGxC,QAAQ,iCAAe,SAAS,eAAe;GAC/C,OAAO;;GAEP,QAAQ,oBAAoB,WAAW;GACvC,OAAO;;GAEP,UAAU,8BAAiB,UAAU,UAAU;GAC/C,OAAO;IACN,UAAU;IACV,uBAAY,SAAS,QAAQ;;;;;GAK9B,QAAQ,iBAAiB;;EAE1B,SAAS,cAAc,MAAM;GAC5B,KAAK","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 45a88d90002041b87f37\n **/","'use strict';\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.service('namedFunction', namedFunction);\r\n\r\n\tfunction namedFunction($dep) {\r\n\t\t$dep.do();\r\n\t}\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/typescript/reference/build.js b/cases/typescript/reference/build.js index 2a5e8c6..7cb4af1 100644 --- a/cases/typescript/reference/build.js +++ b/cases/typescript/reference/build.js @@ -79,7 +79,7 @@ return someCtrl; }()); console.log('after annotated function'); - + /***/ }, /* 1 */ @@ -88,7 +88,7 @@ "use strict"; exports.__esModule = true; exports["default"] = 'babel-test'; - + /***/ } /******/ ]); diff --git a/cases/typescript/reference/build.js.map b/cases/typescript/reference/build.js.map index 47081ef..530375f 100644 --- a/cases/typescript/reference/build.js.map +++ b/cases/typescript/reference/build.js.map @@ -1 +1 @@ -{"version":3,"file":"build.js","sources":["webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\r\nvar to_import_1 = require('./to-import');\r\nconsole.log(to_import_1[\"default\"]);\r\nangular.module('test', [])\r\n .controller('testCtrl', function ($scope) {\r\n})\r\n .factory('testFactory', function ($cacheFactory) {\r\n return {};\r\n})\r\n .service('testNotAnnotated', function () {\r\n return {};\r\n})\r\n .directive('testDirective', function ($timeout) {\r\n return {\r\n restrict: 'E',\r\n controller: function ($scope) {\r\n }\r\n };\r\n})\r\n .controller('someCtrl', someCtrl);\r\nfunction toAnnotate($scope) {\r\n 'ngInject';\r\n console.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\nvar someCtrl = (function () {\r\n function someCtrl($scope) {\r\n this.doSomething();\r\n }\r\n someCtrl.prototype.doSomething = function () {\r\n };\r\n return someCtrl;\r\n}());\r\nconsole.log('after annotated function');\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","\"use strict\";\r\nexports.__esModule = true;\r\nexports[\"default\"] = 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACtCA;;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;AAIA;AACA;AACA;AACA;;AAEA;;AACA;AACA;;AAEA;;AAEA;;AAEA;;;;;;;AChCA;AACA;AACA;;;;","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"build.js","sources":["webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\r\n\r\ndeclare const angular: any;\r\n\r\nimport babelTestMsg from './to-import';\r\nconsole.log(babelTestMsg);\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.controller('someCtrl', someCtrl);\r\n \r\nfunction toAnnotate($scope) {\r\n \t'ngInject';\r\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\n\r\nclass someCtrl {\r\n\tconstructor($scope) {\r\n\t\tthis.doSomething();\r\n\t}\r\n\r\n\tdoSomething() {\r\n\r\n\t}\r\n}\r\n\r\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACtCA;;AAIA;AACA;AAEA;AACA;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;AAKA;AAEA;AACA;AACA;;AAGA;;AACA;AACA;;AAGA;;AAGA;;AAEA;AATA;;;;;;ACjCA;AAAA;AAEA;;;;","sourceRoot":""} \ No newline at end of file diff --git a/run-tests.js b/run-tests.js index 56e1400..3076a41 100644 --- a/run-tests.js +++ b/run-tests.js @@ -13,7 +13,7 @@ if (process.env.NODE_ENV !== 'test') { .pipe(process.stdout); } -const cases = [/*'babel', 'simple',*/ 'typescript']; +const cases = ['typescript', 'babel', 'simple' ]; for (let testCase of cases) { test('Acceptance tests. Case ' + testCase, (t) => { @@ -24,23 +24,25 @@ for (let testCase of cases) { throw err; // hard error } - //console[stats.hasErrors() ? 'error' : 'info'](stats.toString({ - // version: false, - // hash: false, - // assets: true, - // chunks: false, - // colors: true, - //})) + if (stats.hasErrors()) { + console.error(stats.toString({ + version: false, + hash: false, + assets: true, + chunks: false, + colors: true, + })); + } const actualSource = fs.readFileSync(folder + '/dist/build.js', 'utf8'); const expectedSource = fs.readFileSync(folder + '/reference/build.js', 'utf8'); - t.equal(crlf.setLineEnding(actualSource, 'LF'), crlf.setLineEnding(expectedSource, 'LF'), 'Annotated source is valid'); + t.equal(crlf.setLineEnding(actualSource, 'LF'), crlf.setLineEnding(expectedSource, 'LF'), 'Test annotated source passed'); const actualMap = fs.readFileSync(folder + '/dist/build.js.map', 'utf8'); const expectedMap = fs.readFileSync(folder + '/reference/build.js.map', 'utf8'); - t.equal(crlf.setLineEnding(actualMap, 'LF'), crlf.setLineEnding(expectedMap, 'LF'), 'Map is valid') + t.equal(crlf.setLineEnding(actualMap, 'LF'), crlf.setLineEnding(expectedMap, 'LF'), 'Test sourcemap passed') }); t.plan(2); From 7bdc3797cac4a2288fde96e4c05e9532c257eae1 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 16:13:44 +0300 Subject: [PATCH 07/19] *loader pass all tests --- loader.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/loader.js b/loader.js index 9fd9e10..1867ae5 100644 --- a/loader.js +++ b/loader.js @@ -21,8 +21,8 @@ function getOptions(sourceMapEnabled, filename) { if (sourceMapEnabled && options.map === undefined) { options.map = { - inline: false, - inFile: filename, + inline: false, + inFile: filename, }; } @@ -36,47 +36,47 @@ function getOptions(sourceMapEnabled, filename) { function mergeSourceMaps(inputSourceMap, annotateMap) { var outputSourceMap; var sourceMapEnabled = this.sourceMap; - var filename = this.resourcePath; + var filename = normalizePath(this.resourcePath); this.cacheable && this.cacheable(); + if (sourceMapEnabled && !inputSourceMap && annotateMap) { + outputSourceMap = annotateMap; + } + // Using BabelJS as an example, // https://github.com/babel/babel/blob/d3a73b87e9007104cb4fec343f0cfb9e1c67a4ec/packages/babel/src/transformation/file/index.js#L465 // See also vinyl-sourcemaps-apply (used by gulp-ng-annotate) - https://github.com/floridoo/vinyl-sourcemaps-apply/blob/master/index.js - if (sourceMapEnabled && inputSourceMap) { + if (sourceMapEnabled && inputSourceMap) { + inputSourceMap.sources = inputSourceMap.sources.map(function(source) { + var chunks = source.split('!'); + return normalizePath(chunks[chunks.length - 1]); + }); + if (annotateMap) { - // it is important that sources in inputSourceMap be the same as sources in annotateMap, - // in case when using loaders (babel, tsloader, eslint) filenames in sources will be prefixed with loader executable filename. - // we should remove prefix and leave only filename - for(var i = 0; i < inputSourceMap.sources.length; i++) { - var chunks = inputSourceMap.sources[i].split('!'); - inputSourceMap.sources[i] = normalizePath(chunks[chunks.length - 1]); - } - var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap)); generator.applySourceMap(new SourceMapConsumer(inputSourceMap), filename); - + outputSourceMap = generator.toJSON(); - + //Should be set to avoid '../../file is not in SourceMap error https://github.com/huston007/ng-annotate-loader/pull/11' outputSourceMap.sourceRoot = ''; //Copy file name from incoming file because it is empty by some unknown reaon - outputSourceMap.file = inputSourceMap.file; + outputSourceMap.file = normalizePath(this.resourcePath); } else { outputSourceMap = inputSourceMap; } } - + return outputSourceMap; } module.exports = function(source, inputSourceMap) { var sourceMapEnabled = this.sourceMap; var filename = normalizePath(this.resourcePath); - this.cacheable && this.cacheable(); var annotateResult = ngAnnotate(source, getOptions.call(this, sourceMapEnabled, filename)); var outputSourceMap = mergeSourceMaps.call(this, inputSourceMap, annotateResult.map); - + this.callback(null, annotateResult.src || source, outputSourceMap); -}; \ No newline at end of file +}; From 3acaf564f586ff174affc5910e9b17bafbd35e75 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 16:13:59 +0300 Subject: [PATCH 08/19] +update source-maps package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f0594c..999dba2 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "loader-utils": "^0.2.6", "ng-annotate": "1.2.1", "normalize-path": "^2.0.1", - "source-map": "0.5.4" + "source-map": "^0.5.6" }, "devDependencies": { "awesome-typescript-loader": "^1.1.1", From 17130a99e9c5a95e49429fddc2e0c3aa17ad2c0b Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 16:28:28 +0300 Subject: [PATCH 09/19] ~cleanup --- cases/babel/webpack.config.js | 5 +---- cases/typescript/webpack.config.js | 6 ++---- run-tests.js | 12 ++++-------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/cases/babel/webpack.config.js b/cases/babel/webpack.config.js index daf0d10..5d8b8cb 100644 --- a/cases/babel/webpack.config.js +++ b/cases/babel/webpack.config.js @@ -1,10 +1,7 @@ -// Note: this example babel and equires babel-loader -// npm install babel babel-loader - var path = require('path'); module.exports = { - context: __dirname, + context: __dirname, entry: './file-to-annotate.js', output: { path: __dirname + '/dist', diff --git a/cases/typescript/webpack.config.js b/cases/typescript/webpack.config.js index 8faf5ee..512a376 100644 --- a/cases/typescript/webpack.config.js +++ b/cases/typescript/webpack.config.js @@ -1,8 +1,4 @@ -// Note: this example babel and equires babel-loader -// npm install babel babel-loader - var path = require('path'); -const DefinePlugin = require('webpack/lib/DefinePlugin'); module.exports = { context: __dirname, @@ -27,6 +23,8 @@ module.exports = { }, module: { preLoaders: [ + // tslint + awesome-typescript-loader make webpack prefix file path with loader name, and it cause error when merging sourcemaps, + // test that case { test: /\.ts$/, loader: 'tslint-loader', exclude: /node_modules/ }, ], loaders: [ diff --git a/run-tests.js b/run-tests.js index 3076a41..c7d1a8d 100644 --- a/run-tests.js +++ b/run-tests.js @@ -5,15 +5,11 @@ const webpack = require('webpack'); const fs = require('fs'); const crlf = require('crlf-helper'); +test.createStream() + .pipe(require('tap-spec')()) + .pipe(process.stdout); -if (process.env.NODE_ENV !== 'test') { - const tapSpec = require('tap-spec'); - test.createStream() - .pipe(tapSpec()) - .pipe(process.stdout); -} - -const cases = ['typescript', 'babel', 'simple' ]; +const cases = ['typescript', 'babel', 'simple']; for (let testCase of cases) { test('Acceptance tests. Case ' + testCase, (t) => { From 1a038987a214a6e8895c0484e8a121e46d95ef2a Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 16:29:06 +0300 Subject: [PATCH 10/19] +update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 999dba2..8a6cb06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng-annotate-loader", - "version": "0.1.1", + "version": "0.1.2", "description": "Webpack loader that runs ng-annotate on your bundles", "main": "loader.js", "scripts": { From 6e64a67e3404c15baabfe8785575c9bb33ea2589 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 18:01:34 +0300 Subject: [PATCH 11/19] +new test case +another way to solve problem with imputMap.sources --- cases/uglifyjs/file-to-annotate.ts | 43 ++++++++++++++++++++++ cases/uglifyjs/reference/build.js | 2 + cases/uglifyjs/reference/build.js.map | 1 + cases/uglifyjs/to-import.ts | 1 + cases/uglifyjs/webpack.config.js | 53 +++++++++++++++++++++++++++ loader.js | 6 +-- run-tests.js | 2 +- 7 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 cases/uglifyjs/file-to-annotate.ts create mode 100644 cases/uglifyjs/reference/build.js create mode 100644 cases/uglifyjs/reference/build.js.map create mode 100644 cases/uglifyjs/to-import.ts create mode 100644 cases/uglifyjs/webpack.config.js diff --git a/cases/uglifyjs/file-to-annotate.ts b/cases/uglifyjs/file-to-annotate.ts new file mode 100644 index 0000000..8830cbf --- /dev/null +++ b/cases/uglifyjs/file-to-annotate.ts @@ -0,0 +1,43 @@ +'use strict'; + +declare const angular: any; + +import babelTestMsg from './to-import'; +console.log(babelTestMsg); + +angular.module('test', []) + .controller('testCtrl', function($scope) { + + }) + .factory('testFactory', function($cacheFactory) { + return {}; + }) + .service('testNotAnnotated', function() { + return {}; + }) + .directive('testDirective', function ($timeout) { + return { + restrict: 'E', + controller: function($scope) { + + } + }; + }) + .controller('someCtrl', someCtrl); + +function toAnnotate($scope) { + 'ngInject'; + console.log('hi'); // should be function body, otherwise babel remove directive prologue +} + +class someCtrl { + constructor($scope) { + this.doSomething(); + } + + doSomething() { + + } +} + +console.log('after annotated function'); \ No newline at end of file diff --git a/cases/uglifyjs/reference/build.js b/cases/uglifyjs/reference/build.js new file mode 100644 index 0000000..0c9a622 --- /dev/null +++ b/cases/uglifyjs/reference/build.js @@ -0,0 +1,2 @@ +!function(t){function e(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){"use strict";function n(t){"ngInject";console.log("hi")}n.$inject=["$scope"];var r=o(1);console.log(r.default),angular.module("test",[]).controller("testCtrl",["$scope",function(t){}]).factory("testFactory",["$cacheFactory",function(t){return{}}]).service("testNotAnnotated",function(){return{}}).directive("testDirective",["$timeout",function(t){return{restrict:"E",controller:["$scope",function(t){}]}}]).controller("someCtrl",c);var c=function(){function t(t){this.doSomething()}return t.$inject=["$scope"],t.prototype.doSomething=function(){},t}();console.log("after annotated function")},function(t,e){"use strict";e.__esModule=!0,e.default="babel-test"}]); +//# sourceMappingURL=build.js.map \ No newline at end of file diff --git a/cases/uglifyjs/reference/build.js.map b/cases/uglifyjs/reference/build.js.map new file mode 100644 index 0000000..76f669a --- /dev/null +++ b/cases/uglifyjs/reference/build.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///build.js","webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","toAnnotate","$scope","console","log","$inject","to_import_1","angular","controller","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","this","doSomething","prototype","__esModule"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GE5ChC,YA2BA,SAAAW,GAAoBC,GACjB,UACFC,SAAQC,IAAI,MFkBZH,EAAWI,SAAW,SE3CvB,IAAAC,GAAAhB,EAAyB,EACzBa,SAAQC,IAAIE,EAAA,SAEZC,QAAQb,OAAO,WACbc,WAAW,qBAAY,SAASN,OAGhCO,QAAQ,+BAAe,SAASC,GAChC,YAEAC,QAAQ,mBAAoB,WAC5B,WAEAC,UAAU,4BAAiB,SAAUC,GACrC,OACCC,SAAU,IACVN,YAAA,SAAY,SAASN,UAKtBM,WAAW,WAAYO,EAOzB,IAAAA,GAAA,WACC,QAAAA,GAAYb,GACXc,KAAKC,cAMP,MFgCKF,GAASV,SAAW,UEnCxBU,EAAAG,UAAAD,YAAA,aAGDF,IAEAZ,SAAQC,IAAI,6BF2CN,SAASV,EAAQD,GGrFvB,YAAAA,GAAA0B,YAAA,EAEA1B,EAAQ,QAFO","file":"build.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\r\n\ttoAnnotate.$inject = [\"$scope\"];\r\n\tvar to_import_1 = __webpack_require__(1);\r\n\tconsole.log(to_import_1[\"default\"]);\r\n\tangular.module('test', [])\r\n\t .controller('testCtrl', [\"$scope\", function ($scope) {\r\n\t}])\r\n\t .factory('testFactory', [\"$cacheFactory\", function ($cacheFactory) {\r\n\t return {};\r\n\t}])\r\n\t .service('testNotAnnotated', function () {\r\n\t return {};\r\n\t})\r\n\t .directive('testDirective', [\"$timeout\", function ($timeout) {\r\n\t return {\r\n\t restrict: 'E',\r\n\t controller: [\"$scope\", function ($scope) {\r\n\t }]\r\n\t };\r\n\t}])\r\n\t .controller('someCtrl', someCtrl);\r\n\tfunction toAnnotate($scope) {\r\n\t 'ngInject';\r\n\t console.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n\t}\r\n\tvar someCtrl = (function () {\r\n\t someCtrl.$inject = [\"$scope\"];\r\n\t function someCtrl($scope) {\r\n\t this.doSomething();\r\n\t }\r\n\t someCtrl.prototype.doSomething = function () {\r\n\t };\r\n\t return someCtrl;\r\n\t}());\r\n\tconsole.log('after annotated function');\r\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\r\n\texports.__esModule = true;\r\n\texports[\"default\"] = 'babel-test';\r\n\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** build.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\r\n\r\ndeclare const angular: any;\r\n\r\nimport babelTestMsg from './to-import';\r\nconsole.log(babelTestMsg);\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.controller('someCtrl', someCtrl);\r\n \r\nfunction toAnnotate($scope) {\r\n \t'ngInject';\r\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\n\r\nclass someCtrl {\r\n\tconstructor($scope) {\r\n\t\tthis.doSomething();\r\n\t}\r\n\r\n\tdoSomething() {\r\n\r\n\t}\r\n}\r\n\r\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/uglifyjs/to-import.ts b/cases/uglifyjs/to-import.ts new file mode 100644 index 0000000..0475272 --- /dev/null +++ b/cases/uglifyjs/to-import.ts @@ -0,0 +1 @@ +export default 'babel-test'; diff --git a/cases/uglifyjs/webpack.config.js b/cases/uglifyjs/webpack.config.js new file mode 100644 index 0000000..e2b720b --- /dev/null +++ b/cases/uglifyjs/webpack.config.js @@ -0,0 +1,53 @@ +var path = require('path'); +const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'); + +module.exports = { + context: __dirname, + entry: './file-to-annotate', + output: { + path: __dirname + '/dist', + filename: 'build.js' + }, + resolveLoader: { + fallback: path.resolve(__dirname, '../../') + }, + tslint: { + configuration: { + rules: { + quotemark: [true, "double"] + } + }, + }, + resolve: { + extensions: ['.ts'], + root: __dirname, + }, + plugins: [ + /** + * Plugin: UglifyJsPlugin + * Description: Minimize all JavaScript output of chunks. + * Loaders are switched into minimizing mode. + * + * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin + */ + new UglifyJsPlugin({ + beautify: false, + mangle: {screw_ie8: true}, + compress: { + screw_ie8: true, + warnings: false, // don't show unreachable variables etc + }, + comments: false, + }), + ], + module: { + loaders: [ + { + test: /\.ts$/, + loaders: ['loader', 'awesome-typescript-loader'], + }, + ] + }, + debug: true, + devtool: 'source-map' +}; diff --git a/loader.js b/loader.js index 1867ae5..97a2054 100644 --- a/loader.js +++ b/loader.js @@ -47,10 +47,8 @@ function mergeSourceMaps(inputSourceMap, annotateMap) { // https://github.com/babel/babel/blob/d3a73b87e9007104cb4fec343f0cfb9e1c67a4ec/packages/babel/src/transformation/file/index.js#L465 // See also vinyl-sourcemaps-apply (used by gulp-ng-annotate) - https://github.com/floridoo/vinyl-sourcemaps-apply/blob/master/index.js if (sourceMapEnabled && inputSourceMap) { - inputSourceMap.sources = inputSourceMap.sources.map(function(source) { - var chunks = source.split('!'); - return normalizePath(chunks[chunks.length - 1]); - }); + inputSourceMap.sourceRoot = ''; + inputSourceMap.sources[0] = filename; if (annotateMap) { var generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap)); diff --git a/run-tests.js b/run-tests.js index c7d1a8d..b604db3 100644 --- a/run-tests.js +++ b/run-tests.js @@ -9,7 +9,7 @@ test.createStream() .pipe(require('tap-spec')()) .pipe(process.stdout); -const cases = ['typescript', 'babel', 'simple']; +const cases = ['typescript', 'babel', 'simple', 'uglifyjs']; for (let testCase of cases) { test('Acceptance tests. Case ' + testCase, (t) => { From 50e299b6ec7571224ec73abcbeadf11dcf0a9f81 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 19:35:52 +0300 Subject: [PATCH 12/19] +remove hash from maps --- run-tests.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/run-tests.js b/run-tests.js index b604db3..9a6ffc6 100644 --- a/run-tests.js +++ b/run-tests.js @@ -35,12 +35,16 @@ for (let testCase of cases) { t.equal(crlf.setLineEnding(actualSource, 'LF'), crlf.setLineEnding(expectedSource, 'LF'), 'Test annotated source passed'); - const actualMap = fs.readFileSync(folder + '/dist/build.js.map', 'utf8'); - const expectedMap = fs.readFileSync(folder + '/reference/build.js.map', 'utf8'); + const actualMap = prepareMap(fs.readFileSync(folder + '/dist/build.js.map', 'utf8')); + const expectedMap = prepareMap(fs.readFileSync(folder + '/reference/build.js.map', 'utf8')); - t.equal(crlf.setLineEnding(actualMap, 'LF'), crlf.setLineEnding(expectedMap, 'LF'), 'Test sourcemap passed') + t.equal(actualMap, expectedMap, 'Test sourcemap passed'); }); t.plan(2); }); } + +function prepareMap(content){ + return crlf.setLineEnding(content, 'LF').replace(/webpack\/bootstrap [\d\w]+/, 'webpack/bootstrap [hash]'); // remove hash from map +} From e3552997ed242bd7e4517bcb1fc922602d05b19a Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 20:12:27 +0300 Subject: [PATCH 13/19] +remove all hash entries +update webpack --- package.json | 2 +- run-tests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8a6cb06..fe25c80 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,6 @@ "tslint": "^3.15.1", "tslint-loader": "^2.1.5", "typescript": "^1.8.10", - "webpack": "^1.13.1" + "webpack": "^1.13.2" } } diff --git a/run-tests.js b/run-tests.js index 9a6ffc6..a2be265 100644 --- a/run-tests.js +++ b/run-tests.js @@ -46,5 +46,5 @@ for (let testCase of cases) { } function prepareMap(content){ - return crlf.setLineEnding(content, 'LF').replace(/webpack\/bootstrap [\d\w]+/, 'webpack/bootstrap [hash]'); // remove hash from map + return crlf.setLineEnding(content, 'LF').replace(/webpack\/bootstrap [\d\w]+/g, 'webpack/bootstrap [hash]'); // remove hash from map } From be846d503dfed6931ff6fdf5f096c24950c4eec5 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 22:03:25 +0300 Subject: [PATCH 14/19] +prepare map for tests, setLineEndings for sourceContent --- run-tests.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/run-tests.js b/run-tests.js index a2be265..7d7dae6 100644 --- a/run-tests.js +++ b/run-tests.js @@ -38,7 +38,7 @@ for (let testCase of cases) { const actualMap = prepareMap(fs.readFileSync(folder + '/dist/build.js.map', 'utf8')); const expectedMap = prepareMap(fs.readFileSync(folder + '/reference/build.js.map', 'utf8')); - t.equal(actualMap, expectedMap, 'Test sourcemap passed'); + t.deepEqual(actualMap, expectedMap, 'Test sourcemap passed'); }); t.plan(2); @@ -46,5 +46,11 @@ for (let testCase of cases) { } function prepareMap(content){ - return crlf.setLineEnding(content, 'LF').replace(/webpack\/bootstrap [\d\w]+/g, 'webpack/bootstrap [hash]'); // remove hash from map + const map = JSON.parse(content.replace(/webpack\/bootstrap [\d\w]+/g, 'webpack/bootstrap [hash]')); // remove hash from map + + map.sourcesContent = map.sourcesContent.map((sourceContent) => { + return crlf.setLineEnding(sourceContent, 'LF'); + }); + + return map; } From bf2276e3518cb9c25786d834e52d32c1af4d1f76 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 22:22:05 +0300 Subject: [PATCH 15/19] +configure git to not convert line endings to crlf on windows --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf From 4afe66249e5c8332e8b1eae8ec2c61fa24f579c7 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 22:44:49 +0300 Subject: [PATCH 16/19] +test sourcemap more verbose --- run-tests.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/run-tests.js b/run-tests.js index 7d7dae6..4ef4a8f 100644 --- a/run-tests.js +++ b/run-tests.js @@ -33,15 +33,17 @@ for (let testCase of cases) { const actualSource = fs.readFileSync(folder + '/dist/build.js', 'utf8'); const expectedSource = fs.readFileSync(folder + '/reference/build.js', 'utf8'); - t.equal(crlf.setLineEnding(actualSource, 'LF'), crlf.setLineEnding(expectedSource, 'LF'), 'Test annotated source passed'); + t.equal(actualSource, expectedSource, 'Test annotated source'); const actualMap = prepareMap(fs.readFileSync(folder + '/dist/build.js.map', 'utf8')); const expectedMap = prepareMap(fs.readFileSync(folder + '/reference/build.js.map', 'utf8')); - t.deepEqual(actualMap, expectedMap, 'Test sourcemap passed'); + t.deepEqual(actualMap.sourcesContent, expectedMap.sourcesContent, 'Test source map sourceContent'); + t.deepEqual(actualMap.sources, expectedMap.sources, 'Test source map sources'); + t.equal(actualMap.mappings, expectedMap.mappings, 'Test source map mappings'); }); - t.plan(2); + t.plan(4); }); } From 683d614b3480fe94fdae3316c0aab71a9699f09f Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Tue, 30 Aug 2016 22:52:23 +0300 Subject: [PATCH 17/19] +add map generated without crlf --- cases/babel/reference/build.js.map | 2 +- cases/simple/reference/build.js.map | 2 +- cases/typescript/reference/build.js.map | 2 +- cases/uglifyjs/reference/build.js.map | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cases/babel/reference/build.js.map b/cases/babel/reference/build.js.map index 4935cfa..42df0f7 100644 --- a/cases/babel/reference/build.js.map +++ b/cases/babel/reference/build.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap b483f8263e027cd464d5","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":["console","log","angular","module","controller","$scope","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","toAnnotate","doSomething"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAAhiB;;AAIA,KAAI,aAAa,uBAAuB;;AAExC,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,SAAS;;AAEvF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAPhHA,SAAQC,IAAR;;AAEAC,SAAQC,OAAO,QAAQ,IACrBC,WAAW,uBAAY,UAASC,QAAQ,KAGxCC,QAAQ,iCAAe,UAASC,eAAe;EAC/C,OAAO;KAEPC,QAAQ,oBAAoB,YAAW;EACvC,OAAO;IAEPC,UAAU,8BAAiB,UAAUC,UAAU;EAC/C,OAAO;GACNC,UAAU;GACVP,uBAAY,oBAASC,QAAQ;;iBAK9BD,WAAW,UAAYQ;;AAEzB,UAASC,WAAWR,QAAQ;EACzB;;EACFL,QAAQC,IAAI;;;;gCAIc;EAA1B,kBAAYI,QAAQ;GAAA;;GACnB,KAAKS;;;EAMN,aAAa,UAAU,CAAC;GACvB,KAAK;GACL,OAAO,SAAS,cALH;;;EAQd,OAAO;;;AAHRd,SAAQC,IAAI,4B;;;;;;ACxCZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,UALO,a","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b483f8263e027cd464d5\n **/","'use strict';\r\n\r\nimport babelTestMsg from './to-import';\r\nconsole.log(babelTestMsg);\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.controller('someCtrl', someCtrl);\r\n \r\nfunction toAnnotate($scope) {\r\n \t'ngInject';\r\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\n\r\nclass someCtrl {\r\n\tconstructor($scope) {\r\n\t\tthis.doSomething();\r\n\t}\r\n\r\n\tdoSomething() {\r\n\r\n\t}\r\n}\r\n\r\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","export default 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap b483f8263e027cd464d5","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":["console","log","angular","module","controller","$scope","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","toAnnotate","doSomething"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAAhiB;;AAIA,KAAI,aAAa,uBAAuB;;AAExC,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,SAAS;;AAEvF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAPhHA,SAAQC,IAAR;;AAEAC,SAAQC,OAAO,QAAQ,IACrBC,WAAW,uBAAY,UAASC,QAAQ,KAGxCC,QAAQ,iCAAe,UAASC,eAAe;EAC/C,OAAO;KAEPC,QAAQ,oBAAoB,YAAW;EACvC,OAAO;IAEPC,UAAU,8BAAiB,UAAUC,UAAU;EAC/C,OAAO;GACNC,UAAU;GACVP,uBAAY,oBAASC,QAAQ;;iBAK9BD,WAAW,UAAYQ;;AAEzB,UAASC,WAAWR,QAAQ;EACzB;;EACFL,QAAQC,IAAI;;;;gCAIc;EAA1B,kBAAYI,QAAQ;GAAA;;GACnB,KAAKS;;;EAMN,aAAa,UAAU,CAAC;GACvB,KAAK;GACL,OAAO,SAAS,cALH;;;EAQd,OAAO;;;AAHRd,SAAQC,IAAI,4B;;;;;;ACxCZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,UALO,a","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b483f8263e027cd464d5\n **/","'use strict';\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n \t'ngInject';\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/simple/reference/build.js.map b/cases/simple/reference/build.js.map index dc2577b..90d9413 100644 --- a/cases/simple/reference/build.js.map +++ b/cases/simple/reference/build.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 45a88d90002041b87f37","webpack:///./file-to-annotate.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,SAAQ,OAAO,QAAQ;GACrB,WAAW,uBAAY,SAAS,QAAQ;;;GAGxC,QAAQ,iCAAe,SAAS,eAAe;GAC/C,OAAO;;GAEP,QAAQ,oBAAoB,WAAW;GACvC,OAAO;;GAEP,UAAU,8BAAiB,UAAU,UAAU;GAC/C,OAAO;IACN,UAAU;IACV,uBAAY,SAAS,QAAQ;;;;;GAK9B,QAAQ,iBAAiB;;EAE1B,SAAS,cAAc,MAAM;GAC5B,KAAK","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 45a88d90002041b87f37\n **/","'use strict';\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.service('namedFunction', namedFunction);\r\n\r\n\tfunction namedFunction($dep) {\r\n\t\t$dep.do();\r\n\t}\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap 85afe4302993de1e11d4","webpack:///./file-to-annotate.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,SAAQ,OAAO,QAAQ;GACrB,WAAW,uBAAY,SAAS,QAAQ;;;GAGxC,QAAQ,iCAAe,SAAS,eAAe;GAC/C,OAAO;;GAEP,QAAQ,oBAAoB,WAAW;GACvC,OAAO;;GAEP,UAAU,8BAAiB,UAAU,UAAU;GAC/C,OAAO;IACN,UAAU;IACV,uBAAY,SAAS,QAAQ;;;;;GAK9B,QAAQ,iBAAiB;;EAE1B,SAAS,cAAc,MAAM;GAC5B,KAAK","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 85afe4302993de1e11d4\n **/","'use strict';\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.service('namedFunction', namedFunction);\n\n\tfunction namedFunction($dep) {\n\t\t$dep.do();\n\t}\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/typescript/reference/build.js.map b/cases/typescript/reference/build.js.map index 530375f..4298351 100644 --- a/cases/typescript/reference/build.js.map +++ b/cases/typescript/reference/build.js.map @@ -1 +1 @@ -{"version":3,"file":"build.js","sources":["webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\r\n\r\ndeclare const angular: any;\r\n\r\nimport babelTestMsg from './to-import';\r\nconsole.log(babelTestMsg);\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.controller('someCtrl', someCtrl);\r\n \r\nfunction toAnnotate($scope) {\r\n \t'ngInject';\r\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\n\r\nclass someCtrl {\r\n\tconstructor($scope) {\r\n\t\tthis.doSomething();\r\n\t}\r\n\r\n\tdoSomething() {\r\n\r\n\t}\r\n}\r\n\r\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACtCA;;AAIA;AACA;AAEA;AACA;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;AAKA;AAEA;AACA;AACA;;AAGA;;AACA;AACA;;AAGA;;AAGA;;AAEA;AATA;;;;;;ACjCA;AAAA;AAEA;;;;","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"build.js","sources":["webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\n\ndeclare const angular: any;\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n \t'ngInject';\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACtCA;;AAIA;AACA;AAEA;AACA;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;AAKA;AAEA;AACA;AACA;;AAGA;;AACA;AACA;;AAGA;;AAGA;;AAEA;AATA;;;;;;ACjCA;AAAA;AAEA;;;;","sourceRoot":""} \ No newline at end of file diff --git a/cases/uglifyjs/reference/build.js.map b/cases/uglifyjs/reference/build.js.map index 76f669a..6bc8bf2 100644 --- a/cases/uglifyjs/reference/build.js.map +++ b/cases/uglifyjs/reference/build.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///build.js","webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","toAnnotate","$scope","console","log","$inject","to_import_1","angular","controller","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","this","doSomething","prototype","__esModule"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GE5ChC,YA2BA,SAAAW,GAAoBC,GACjB,UACFC,SAAQC,IAAI,MFkBZH,EAAWI,SAAW,SE3CvB,IAAAC,GAAAhB,EAAyB,EACzBa,SAAQC,IAAIE,EAAA,SAEZC,QAAQb,OAAO,WACbc,WAAW,qBAAY,SAASN,OAGhCO,QAAQ,+BAAe,SAASC,GAChC,YAEAC,QAAQ,mBAAoB,WAC5B,WAEAC,UAAU,4BAAiB,SAAUC,GACrC,OACCC,SAAU,IACVN,YAAA,SAAY,SAASN,UAKtBM,WAAW,WAAYO,EAOzB,IAAAA,GAAA,WACC,QAAAA,GAAYb,GACXc,KAAKC,cAMP,MFgCKF,GAASV,SAAW,UEnCxBU,EAAAG,UAAAD,YAAA,aAGDF,IAEAZ,SAAQC,IAAI,6BF2CN,SAASV,EAAQD,GGrFvB,YAAAA,GAAA0B,YAAA,EAEA1B,EAAQ,QAFO","file":"build.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\r\n\ttoAnnotate.$inject = [\"$scope\"];\r\n\tvar to_import_1 = __webpack_require__(1);\r\n\tconsole.log(to_import_1[\"default\"]);\r\n\tangular.module('test', [])\r\n\t .controller('testCtrl', [\"$scope\", function ($scope) {\r\n\t}])\r\n\t .factory('testFactory', [\"$cacheFactory\", function ($cacheFactory) {\r\n\t return {};\r\n\t}])\r\n\t .service('testNotAnnotated', function () {\r\n\t return {};\r\n\t})\r\n\t .directive('testDirective', [\"$timeout\", function ($timeout) {\r\n\t return {\r\n\t restrict: 'E',\r\n\t controller: [\"$scope\", function ($scope) {\r\n\t }]\r\n\t };\r\n\t}])\r\n\t .controller('someCtrl', someCtrl);\r\n\tfunction toAnnotate($scope) {\r\n\t 'ngInject';\r\n\t console.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n\t}\r\n\tvar someCtrl = (function () {\r\n\t someCtrl.$inject = [\"$scope\"];\r\n\t function someCtrl($scope) {\r\n\t this.doSomething();\r\n\t }\r\n\t someCtrl.prototype.doSomething = function () {\r\n\t };\r\n\t return someCtrl;\r\n\t}());\r\n\tconsole.log('after annotated function');\r\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\r\n\texports.__esModule = true;\r\n\texports[\"default\"] = 'babel-test';\r\n\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** build.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\r\n\r\ndeclare const angular: any;\r\n\r\nimport babelTestMsg from './to-import';\r\nconsole.log(babelTestMsg);\r\n\r\nangular.module('test', [])\r\n\t.controller('testCtrl', function($scope) {\r\n\r\n\t})\r\n\t.factory('testFactory', function($cacheFactory) {\r\n\t\treturn {};\r\n\t})\r\n\t.service('testNotAnnotated', function() {\r\n\t\treturn {};\r\n\t})\r\n\t.directive('testDirective', function ($timeout) {\r\n\t\treturn {\r\n\t\t\trestrict: 'E',\r\n\t\t\tcontroller: function($scope) {\r\n\r\n\t\t\t}\r\n\t\t};\r\n\t})\r\n\t.controller('someCtrl', someCtrl);\r\n \r\nfunction toAnnotate($scope) {\r\n \t'ngInject';\r\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n}\r\n\r\nclass someCtrl {\r\n\tconstructor($scope) {\r\n\t\tthis.doSomething();\r\n\t}\r\n\r\n\tdoSomething() {\r\n\r\n\t}\r\n}\r\n\r\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\r\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///build.js","webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","toAnnotate","$scope","console","log","$inject","to_import_1","angular","controller","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","this","doSomething","prototype","__esModule"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GE5ChC,YA2BA,SAAAW,GAAoBC,GACjB,UACFC,SAAQC,IAAI,MFkBZH,EAAWI,SAAW,SE3CvB,IAAAC,GAAAhB,EAAyB,EACzBa,SAAQC,IAAIE,EAAA,SAEZC,QAAQb,OAAO,WACbc,WAAW,qBAAY,SAASN,OAGhCO,QAAQ,+BAAe,SAASC,GAChC,YAEAC,QAAQ,mBAAoB,WAC5B,WAEAC,UAAU,4BAAiB,SAAUC,GACrC,OACCC,SAAU,IACVN,YAAA,SAAY,SAASN,UAKtBM,WAAW,WAAYO,EAOzB,IAAAA,GAAA,WACC,QAAAA,GAAYb,GACXc,KAAKC,cAMP,MFgCKF,GAASV,SAAW,UEnCxBU,EAAAG,UAAAD,YAAA,aAGDF,IAEAZ,SAAQC,IAAI,6BF2CN,SAASV,EAAQD,GGrFvB,YAAAA,GAAA0B,YAAA,EAEA1B,EAAQ,QAFO","file":"build.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\r\n\ttoAnnotate.$inject = [\"$scope\"];\r\n\tvar to_import_1 = __webpack_require__(1);\r\n\tconsole.log(to_import_1[\"default\"]);\r\n\tangular.module('test', [])\r\n\t .controller('testCtrl', [\"$scope\", function ($scope) {\r\n\t}])\r\n\t .factory('testFactory', [\"$cacheFactory\", function ($cacheFactory) {\r\n\t return {};\r\n\t}])\r\n\t .service('testNotAnnotated', function () {\r\n\t return {};\r\n\t})\r\n\t .directive('testDirective', [\"$timeout\", function ($timeout) {\r\n\t return {\r\n\t restrict: 'E',\r\n\t controller: [\"$scope\", function ($scope) {\r\n\t }]\r\n\t };\r\n\t}])\r\n\t .controller('someCtrl', someCtrl);\r\n\tfunction toAnnotate($scope) {\r\n\t 'ngInject';\r\n\t console.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n\t}\r\n\tvar someCtrl = (function () {\r\n\t someCtrl.$inject = [\"$scope\"];\r\n\t function someCtrl($scope) {\r\n\t this.doSomething();\r\n\t }\r\n\t someCtrl.prototype.doSomething = function () {\r\n\t };\r\n\t return someCtrl;\r\n\t}());\r\n\tconsole.log('after annotated function');\r\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\r\n\texports.__esModule = true;\r\n\texports[\"default\"] = 'babel-test';\r\n\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** build.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\n\ndeclare const angular: any;\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n \t'ngInject';\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"sourceRoot":""} \ No newline at end of file From 85f6b9c863496f8edb83699b474b475bea9f75c3 Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Wed, 31 Aug 2016 15:26:29 +0300 Subject: [PATCH 18/19] +if ngAnnotate do nothing, return map and result untouched --- loader.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/loader.js b/loader.js index 97a2054..c167d41 100644 --- a/loader.js +++ b/loader.js @@ -74,7 +74,12 @@ module.exports = function(source, inputSourceMap) { this.cacheable && this.cacheable(); var annotateResult = ngAnnotate(source, getOptions.call(this, sourceMapEnabled, filename)); - var outputSourceMap = mergeSourceMaps.call(this, inputSourceMap, annotateResult.map); - this.callback(null, annotateResult.src || source, outputSourceMap); + if (annotateResult.src !== source) { + var outputSourceMap = mergeSourceMaps.call(this, inputSourceMap, annotateResult.map); + this.callback(null, annotateResult.src || source, outputSourceMap); + } else { + // if ngAnnotate do nothing, return map and result untouched + this.callback(null, source, inputSourceMap); + } }; From 1f3bdcdb129959deec70a4fae12f2c19752bc85f Mon Sep 17 00:00:00 2001 From: Yatsenko Date: Thu, 8 Sep 2016 15:00:30 +0300 Subject: [PATCH 19/19] +change sourcemap testing way --- cases/babel/reference/build.js.map | 1 - .../babel/reference/sourcemap-checkpoints.js | 10 ++++ cases/simple/reference/build.js.map | 1 - .../simple/reference/sourcemap-checkpoints.js | 10 ++++ cases/typescript/reference/build.js.map | 1 - .../reference/sourcemap-checkpoints.js | 14 ++++++ cases/uglifyjs/reference/build.js.map | 1 - .../reference/sourcemap-checkpoints.js | 14 ++++++ loader.js | 2 +- run-tests.js | 47 +++++++++++++------ 10 files changed, 82 insertions(+), 19 deletions(-) delete mode 100644 cases/babel/reference/build.js.map create mode 100644 cases/babel/reference/sourcemap-checkpoints.js delete mode 100644 cases/simple/reference/build.js.map create mode 100644 cases/simple/reference/sourcemap-checkpoints.js delete mode 100644 cases/typescript/reference/build.js.map create mode 100644 cases/typescript/reference/sourcemap-checkpoints.js delete mode 100644 cases/uglifyjs/reference/build.js.map create mode 100644 cases/uglifyjs/reference/sourcemap-checkpoints.js diff --git a/cases/babel/reference/build.js.map b/cases/babel/reference/build.js.map deleted file mode 100644 index 42df0f7..0000000 --- a/cases/babel/reference/build.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap b483f8263e027cd464d5","webpack:///./file-to-annotate.js","webpack:///./to-import.js"],"names":["console","log","angular","module","controller","$scope","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","toAnnotate","doSomething"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,KAAI,eAAe,YAAY,EAAE,SAAS,iBAAiB,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,EAAE,IAAI,aAAa,MAAM,IAAI,WAAW,aAAa,WAAW,cAAc,OAAO,WAAW,eAAe,MAAM,IAAI,WAAW,YAAY,WAAW,WAAW,MAAM,OAAO,eAAe,QAAQ,WAAW,KAAK,iBAAiB,OAAO,UAAU,aAAa,YAAY,aAAa,EAAE,IAAI,YAAY,iBAAiB,YAAY,WAAW,aAAa,IAAI,aAAa,iBAAiB,aAAa,cAAc,OAAO;;AAAhiB;;AAIA,KAAI,aAAa,uBAAuB;;AAExC,UAAS,uBAAuB,KAAK,EAAE,OAAO,OAAO,IAAI,aAAa,MAAM,EAAE,SAAS;;AAEvF,UAAS,gBAAgB,UAAU,aAAa,EAAE,IAAI,EAAE,oBAAoB,cAAc,EAAE,MAAM,IAAI,UAAU;;AAPhHA,SAAQC,IAAR;;AAEAC,SAAQC,OAAO,QAAQ,IACrBC,WAAW,uBAAY,UAASC,QAAQ,KAGxCC,QAAQ,iCAAe,UAASC,eAAe;EAC/C,OAAO;KAEPC,QAAQ,oBAAoB,YAAW;EACvC,OAAO;IAEPC,UAAU,8BAAiB,UAAUC,UAAU;EAC/C,OAAO;GACNC,UAAU;GACVP,uBAAY,oBAASC,QAAQ;;iBAK9BD,WAAW,UAAYQ;;AAEzB,UAASC,WAAWR,QAAQ;EACzB;;EACFL,QAAQC,IAAI;;;;gCAIc;EAA1B,kBAAYI,QAAQ;GAAA;;GACnB,KAAKS;;;EAMN,aAAa,UAAU,CAAC;GACvB,KAAK;GACL,OAAO,SAAS,cALH;;;EAQd,OAAO;;;AAHRd,SAAQC,IAAI,4B;;;;;;ACxCZ;;AAEA,QAAO,eAAe,SAAS,cAAc;GAC3C,OAAO;;AAET,SAAQ,UALO,a","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap b483f8263e027cd464d5\n **/","'use strict';\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n \t'ngInject';\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/babel/reference/sourcemap-checkpoints.js b/cases/babel/reference/sourcemap-checkpoints.js new file mode 100644 index 0000000..88909bb --- /dev/null +++ b/cases/babel/reference/sourcemap-checkpoints.js @@ -0,0 +1,10 @@ +module.exports = [ + { + original: { source: 'webpack:///file-to-annotate.js', line: 33, column: 2 }, + generated: { line: 84, column: 3}, + }, + { + original: { source: 'webpack:///file-to-annotate.js', line: 41, column: 0 }, + generated: { line: 95, column: 0 }, + }, +]; diff --git a/cases/simple/reference/build.js.map b/cases/simple/reference/build.js.map deleted file mode 100644 index 90d9413..0000000 --- a/cases/simple/reference/build.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 85afe4302993de1e11d4","webpack:///./file-to-annotate.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;AAEA,SAAQ,OAAO,QAAQ;GACrB,WAAW,uBAAY,SAAS,QAAQ;;;GAGxC,QAAQ,iCAAe,SAAS,eAAe;GAC/C,OAAO;;GAEP,QAAQ,oBAAoB,WAAW;GACvC,OAAO;;GAEP,UAAU,8BAAiB,UAAU,UAAU;GAC/C,OAAO;IACN,UAAU;IACV,uBAAY,SAAS,QAAQ;;;;;GAK9B,QAAQ,iBAAiB;;EAE1B,SAAS,cAAc,MAAM;GAC5B,KAAK","file":"build.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 85afe4302993de1e11d4\n **/","'use strict';\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.service('namedFunction', namedFunction);\n\n\tfunction namedFunction($dep) {\n\t\t$dep.do();\n\t}\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/simple/reference/sourcemap-checkpoints.js b/cases/simple/reference/sourcemap-checkpoints.js new file mode 100644 index 0000000..2797c7f --- /dev/null +++ b/cases/simple/reference/sourcemap-checkpoints.js @@ -0,0 +1,10 @@ +module.exports = [ + { + original: { source: 'webpack:///file-to-annotate.js', line: 24, column: 5 }, + generated: { line: 71, column: 3}, + }, + { + original: { source: 'webpack:///file-to-annotate.js', line: 11, column: 5 }, + generated: { line: 58, column: 3 }, + }, +]; diff --git a/cases/typescript/reference/build.js.map b/cases/typescript/reference/build.js.map deleted file mode 100644 index 4298351..0000000 --- a/cases/typescript/reference/build.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"build.js","sources":["webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\n\ndeclare const angular: any;\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n \t'ngInject';\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;ACtCA;;AAIA;AACA;AAEA;AACA;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;AAKA;AAEA;AACA;AACA;;AAGA;;AACA;AACA;;AAGA;;AAGA;;AAEA;AATA;;;;;;ACjCA;AAAA;AAEA;;;;","sourceRoot":""} \ No newline at end of file diff --git a/cases/typescript/reference/sourcemap-checkpoints.js b/cases/typescript/reference/sourcemap-checkpoints.js new file mode 100644 index 0000000..f010fde --- /dev/null +++ b/cases/typescript/reference/sourcemap-checkpoints.js @@ -0,0 +1,14 @@ +module.exports = [ + { + original: { source: 'webpack:///file-to-annotate.ts', line: 6, column: 0 }, + generated: { line: 50, column: 0}, + }, + { + original: { source: 'webpack:///file-to-annotate.ts', line: 16, column: 5 }, + generated: { line: 58, column: 0 }, + }, + { + original: { source: 'webpack:///file-to-annotate.ts', line: 30, column: 3 }, + generated: { line: 70, column: 0 }, + }, +]; diff --git a/cases/uglifyjs/reference/build.js.map b/cases/uglifyjs/reference/build.js.map deleted file mode 100644 index 6bc8bf2..0000000 --- a/cases/uglifyjs/reference/build.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack:///build.js","webpack:///webpack/bootstrap 73a3d93da22d6ca79e57","webpack:///./file-to-annotate.ts","webpack:///./to-import.ts"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","id","loaded","call","m","c","p","toAnnotate","$scope","console","log","$inject","to_import_1","angular","controller","factory","$cacheFactory","service","directive","$timeout","restrict","someCtrl","this","doSomething","prototype","__esModule"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GE5ChC,YA2BA,SAAAW,GAAoBC,GACjB,UACFC,SAAQC,IAAI,MFkBZH,EAAWI,SAAW,SE3CvB,IAAAC,GAAAhB,EAAyB,EACzBa,SAAQC,IAAIE,EAAA,SAEZC,QAAQb,OAAO,WACbc,WAAW,qBAAY,SAASN,OAGhCO,QAAQ,+BAAe,SAASC,GAChC,YAEAC,QAAQ,mBAAoB,WAC5B,WAEAC,UAAU,4BAAiB,SAAUC,GACrC,OACCC,SAAU,IACVN,YAAA,SAAY,SAASN,UAKtBM,WAAW,WAAYO,EAOzB,IAAAA,GAAA,WACC,QAAAA,GAAYb,GACXc,KAAKC,cAMP,MFgCKF,GAASV,SAAW,UEnCxBU,EAAAG,UAAAD,YAAA,aAGDF,IAEAZ,SAAQC,IAAI,6BF2CN,SAASV,EAAQD,GGrFvB,YAAAA,GAAA0B,YAAA,EAEA1B,EAAQ,QAFO","file":"build.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t'use strict';\r\n\ttoAnnotate.$inject = [\"$scope\"];\r\n\tvar to_import_1 = __webpack_require__(1);\r\n\tconsole.log(to_import_1[\"default\"]);\r\n\tangular.module('test', [])\r\n\t .controller('testCtrl', [\"$scope\", function ($scope) {\r\n\t}])\r\n\t .factory('testFactory', [\"$cacheFactory\", function ($cacheFactory) {\r\n\t return {};\r\n\t}])\r\n\t .service('testNotAnnotated', function () {\r\n\t return {};\r\n\t})\r\n\t .directive('testDirective', [\"$timeout\", function ($timeout) {\r\n\t return {\r\n\t restrict: 'E',\r\n\t controller: [\"$scope\", function ($scope) {\r\n\t }]\r\n\t };\r\n\t}])\r\n\t .controller('someCtrl', someCtrl);\r\n\tfunction toAnnotate($scope) {\r\n\t 'ngInject';\r\n\t console.log('hi'); // should be function body, otherwise babel remove directive prologue\r\n\t}\r\n\tvar someCtrl = (function () {\r\n\t someCtrl.$inject = [\"$scope\"];\r\n\t function someCtrl($scope) {\r\n\t this.doSomething();\r\n\t }\r\n\t someCtrl.prototype.doSomething = function () {\r\n\t };\r\n\t return someCtrl;\r\n\t}());\r\n\tconsole.log('after annotated function');\r\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports) {\n\n\t\"use strict\";\r\n\texports.__esModule = true;\r\n\texports[\"default\"] = 'babel-test';\r\n\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** build.js\n **/"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 73a3d93da22d6ca79e57\n **/","'use strict';\n\ndeclare const angular: any;\n\nimport babelTestMsg from './to-import';\nconsole.log(babelTestMsg);\n\nangular.module('test', [])\n\t.controller('testCtrl', function($scope) {\n\n\t})\n\t.factory('testFactory', function($cacheFactory) {\n\t\treturn {};\n\t})\n\t.service('testNotAnnotated', function() {\n\t\treturn {};\n\t})\n\t.directive('testDirective', function ($timeout) {\n\t\treturn {\n\t\t\trestrict: 'E',\n\t\t\tcontroller: function($scope) {\n\n\t\t\t}\n\t\t};\n\t})\n\t.controller('someCtrl', someCtrl);\n \nfunction toAnnotate($scope) {\n \t'ngInject';\n\tconsole.log('hi'); // should be function body, otherwise babel remove directive prologue\n}\n\nclass someCtrl {\n\tconstructor($scope) {\n\t\tthis.doSomething();\n\t}\n\n\tdoSomething() {\n\n\t}\n}\n\nconsole.log('after annotated function');\n\n\n/** WEBPACK FOOTER **\n ** ./file-to-annotate.ts\n **/","export default 'babel-test';\n\n\n\n/** WEBPACK FOOTER **\n ** ./to-import.ts\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/cases/uglifyjs/reference/sourcemap-checkpoints.js b/cases/uglifyjs/reference/sourcemap-checkpoints.js new file mode 100644 index 0000000..c181bdc --- /dev/null +++ b/cases/uglifyjs/reference/sourcemap-checkpoints.js @@ -0,0 +1,14 @@ +module.exports = [ + { + original: { source: 'webpack:///file-to-annotate.ts', line: 6, column: 0 }, + generated: { line: 1, column: 303}, + }, + { + original: { source: 'webpack:///file-to-annotate.ts', line: 16, column: 5 }, + generated: { line: 1, column: 502 }, + }, + { + original: { source: 'webpack:///file-to-annotate.ts', line: 30, column: 3 }, + generated: { line: 1, column: 253 }, + }, +]; diff --git a/loader.js b/loader.js index c167d41..d1f3942 100644 --- a/loader.js +++ b/loader.js @@ -5,7 +5,7 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator; var normalizePath = require('normalize-path'); function loadPlugins(pluginNames) { - var pluginNames = pluginNames || []; + pluginNames = pluginNames || []; return pluginNames.map(function(name) { return require(name); }); diff --git a/run-tests.js b/run-tests.js index 4ef4a8f..726cec4 100644 --- a/run-tests.js +++ b/run-tests.js @@ -3,13 +3,13 @@ const test = require('tape'); const webpack = require('webpack'); const fs = require('fs'); -const crlf = require('crlf-helper'); +const SourceMapConsumer = require('source-map').SourceMapConsumer; test.createStream() .pipe(require('tap-spec')()) .pipe(process.stdout); -const cases = ['typescript', 'babel', 'simple', 'uglifyjs']; +const cases = ['typescript','simple', 'babel', 'uglifyjs']; for (let testCase of cases) { test('Acceptance tests. Case ' + testCase, (t) => { @@ -35,24 +35,43 @@ for (let testCase of cases) { t.equal(actualSource, expectedSource, 'Test annotated source'); - const actualMap = prepareMap(fs.readFileSync(folder + '/dist/build.js.map', 'utf8')); - const expectedMap = prepareMap(fs.readFileSync(folder + '/reference/build.js.map', 'utf8')); - - t.deepEqual(actualMap.sourcesContent, expectedMap.sourcesContent, 'Test source map sourceContent'); - t.deepEqual(actualMap.sources, expectedMap.sources, 'Test source map sources'); - t.equal(actualMap.mappings, expectedMap.mappings, 'Test source map mappings'); + const actualMap = fs.readFileSync(folder + '/dist/build.js.map', 'utf8'); + testMap(t, actualMap, require(folder + '/reference/sourcemap-checkpoints')); }); - t.plan(4); + t.plan(2); }); } -function prepareMap(content){ - const map = JSON.parse(content.replace(/webpack\/bootstrap [\d\w]+/g, 'webpack/bootstrap [hash]')); // remove hash from map +/** + * + * @param t + * @param content + * @param {array<{original, generated}>} checkpoints + */ +function testMap(t, content, checkpoints){ + t.test('Check source map cases', (t) => { + const rawMap = JSON.parse(content); + const map = new SourceMapConsumer(rawMap); + + const sources = rawMap.sources.map((source) => { + const matches = source.match(/[^/]+\..+$/); + return matches ? matches[0] : source; + }); + + t.equal(sources.length, uniq(sources).length, 'No duplicates in sourcemap sources'); - map.sourcesContent = map.sourcesContent.map((sourceContent) => { - return crlf.setLineEnding(sourceContent, 'LF'); + for(let point of checkpoints) { + const result = map.generatedPositionFor(point.original); + + t.deepEqual({line: result.line, column: result.column}, point.generated); + } }); - return map; + t.end(); +} + + +function uniq(a) { + return Array.from(new Set(a)); }