google-closure-compiler 20180716.0.1 → 20181008.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -148,7 +148,7 @@ const closureCompiler = new ClosureCompiler({
148
148
  compilation_level: 'ADVANCED'
149
149
  });
150
150
 
151
- const compilerProcess = closureCompiler.run(function(exitCode, stdOut, stdErr) {
151
+ const compilerProcess = closureCompiler.run((exitCode, stdOut, stdErr) => {
152
152
  //compilation complete
153
153
  });
154
154
  ```
@@ -164,13 +164,13 @@ const closureCompiler = new ClosureCompiler({
164
164
  compilation_level: 'ADVANCED'
165
165
  });
166
166
 
167
- const compilerProcess = closureCompiler.run(function(exitCode, stdOut, stdErr) {
168
- //compilation complete
169
- }, [{
167
+ const compilerProcess = closureCompiler.run([{
170
168
  path: 'file-one.js',
171
169
  src: 'alert("hello world")',
172
170
  sourceMap: null // optional input source map
173
- }]);
171
+ }], (exitCode, stdOut, stdErr) => {
172
+ //compilation complete
173
+ });
174
174
  ```
175
175
 
176
176
  ## License
package/cli.js CHANGED
@@ -1,9 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
  const fs = require('fs');
4
- const {getNativeImagePath, getFirstSupportedPlatform, parseCliFlags} = require('./lib/utils');
4
+ const path = require('path');
5
+ const {getNativeImagePath, getFirstSupportedPlatform} = require('./lib/utils');
6
+ const parseArgs = require('minimist');
5
7
 
6
- const compilerFlags = parseCliFlags(process.argv.slice(2));
8
+ /** @see https://stackoverflow.com/a/40686853/1211524 */
9
+ function mkDirByPathSync(targetDir, {isRelativeToScript = false} = {}) {
10
+ const sep = path.sep;
11
+ const initDir = path.isAbsolute(targetDir) ? sep : '';
12
+ const baseDir = isRelativeToScript ? __dirname : '.';
13
+
14
+ targetDir.split(sep).reduce((parentDir, childDir) => {
15
+ const curDir = path.resolve(baseDir, parentDir, childDir);
16
+ try {
17
+ fs.mkdirSync(curDir);
18
+ } catch (err) {
19
+ if (err.code !== 'EEXIST') {
20
+ throw err;
21
+ }
22
+ }
23
+
24
+ return curDir;
25
+ }, initDir);
26
+ }
27
+
28
+ const compilerFlags = parseArgs(process.argv.slice(2));
29
+
30
+ // The platform flag is only used by this cli script - it is not natively supported by any compiler version.
31
+ // If it exists, use the value, but then delete it so that it's not actually passed to the compiler.
7
32
  let platform;
8
33
  if (compilerFlags.hasOwnProperty('platform')) {
9
34
  platform = compilerFlags.platform;
@@ -12,6 +37,35 @@ if (compilerFlags.hasOwnProperty('platform')) {
12
37
  platform = getFirstSupportedPlatform(['native', 'java', 'javascript']);
13
38
  }
14
39
 
40
+ // The compiler treats default arguments as if they were --js args.
41
+ // Minimist parses default arguments and puts them under the '_' key.
42
+ // Move the '_' key to the 'js' key.
43
+ if (compilerFlags.hasOwnProperty('_') && compilerFlags['_'].length > 0) {
44
+ let existingJsFlags = [];
45
+ if (compilerFlags.js) {
46
+ if (Array.isArray(compilerFlags.js)) {
47
+ existingJsFlags = compilerFlags.js;
48
+ } else {
49
+ existingJsFlags = [compilerFlags.js];
50
+ }
51
+ }
52
+ compilerFlags.js = existingJsFlags.concat(compilerFlags['_']);
53
+ delete compilerFlags['_'];
54
+ } else {
55
+ delete compilerFlags['_'];
56
+ }
57
+
58
+ // Boolean arguments can in some cases be parsed as strings.
59
+ // Since its highly unlikely that an argument actually needs to be the strings 'true' or 'false',
60
+ // convert them to true booleans.
61
+ Object.keys(compilerFlags).forEach(flag => {
62
+ if (compilerFlags[flag] === 'true') {
63
+ compilerFlags[flag] = true;
64
+ } else if (compilerFlags[flag] === 'false') {
65
+ compilerFlags[flag] = false;
66
+ }
67
+ });
68
+
15
69
  if (platform !== 'javascript') {
16
70
  const Compiler = require('./lib/node/closure-compiler');
17
71
  let args = process.argv.slice(2);
@@ -39,101 +93,86 @@ if (platform !== 'javascript') {
39
93
  });
40
94
  } else {
41
95
  if (compilerFlags.help === true) {
42
- console.log('Sample usage: --compilation_level (-O) VAL --externs VAL --js VAL --js_output_file VAL --warning_level (-W) [QUIET | DEFAULT | VERBOSE]');
43
- console.log('See https://github.com/google/closure-compiler/wiki/Flags-and-Options for the full list of flags');
96
+ process.stdout.write('Sample usage: --compilation_level (-O) VAL --externs VAL --js VAL --js_output_file VAL --warning_level (-W) [QUIET | DEFAULT | VERBOSE]\n');
97
+ process.stdout.write('See https://github.com/google/closure-compiler/wiki/Flags-and-Options for the full list of flags`);\n');
44
98
  process.exit(0);
45
99
  }
46
100
 
47
101
  if (compilerFlags.version === true) {
48
102
  const {version} = require('./package.json');
49
- console.log(`Version: ${version}`);
103
+ process.stdout.write(`Version: ${version}\n`);
50
104
  process.exit(0);
51
105
  }
52
106
 
53
- let inputFilePromises = [];
54
107
  let waitOnStdIn = true;
55
108
  if (compilerFlags.js) {
56
109
  waitOnStdIn = false;
57
- if (!Array.isArray(compilerFlags.js)) {
58
- compilerFlags.js = [compilerFlags.js];
59
- }
60
- inputFilePromises = compilerFlags.js.map(path =>
61
- new Promise((resolve, reject) =>
62
- fs.readFile(path, 'utf8', (err, src) => err ? reject(err) : resolve({src, path})))
63
- .catch(e => {
64
- process.exitCode = 1;
65
- console.error(e);
66
- }));
67
-
68
- delete compilerFlags.js;
69
- }
70
- let externFilePromises = [];
71
- if (compilerFlags.externs) {
72
- if (!Array.isArray(compilerFlags.externs)) {
73
- compilerFlags.externs = [compilerFlags.externs];
74
- }
75
- externFilePromises = compilerFlags.externs.map(path =>
76
- new Promise((resolve, reject) =>
77
- fs.readFile(path, 'utf8', (err, src) => err ? reject(err) : resolve({src, path})))
78
- .catch(e => {
79
- process.exitCode = 1;
80
- console.error(e);
81
- }));
82
-
83
- delete compilerFlags.externs;
84
110
  }
85
111
 
86
- Promise.all([...inputFilePromises, ...externFilePromises])
87
- .then(files => {
88
- const inputFiles = files.slice(0, inputFilePromises.length);
89
- const externs = files.slice(inputFilePromises.length);
90
- if (externs.length > 0) {
91
- compilerFlags.externs = externs;
92
- } else {
93
- delete compilerFlags.externs;
112
+ // Mimic the behavior of the java version and wait for input from standard if there
113
+ // are no --js flags
114
+ const getFilesFromStdin = !waitOnStdIn ? Promise.resolve([]) : new Promise(resolve => {
115
+ let stdInData = '';
116
+ const waitingTimeout = setTimeout(() => {
117
+ process.stderr.write('The compiler is waiting for input via stdin.\n');
118
+ }, 1000);
119
+ process.stdin.setEncoding('utf8');
120
+ process.stdin.on('readable', () => {
121
+ const chunk = process.stdin.read();
122
+ if (chunk !== null) {
123
+ stdInData += chunk;
124
+ clearTimeout(waitingTimeout);
94
125
  }
95
-
96
- if (!waitOnStdIn) {
97
- return inputFiles;
126
+ });
127
+ process.stdin.on('error', (err) => {
128
+ process.exitCode = 1;
129
+ console.error(err);
130
+ clearTimeout(waitingTimeout);
131
+ });
132
+ process.stdin.on('end', () => {
133
+ if (stdInData.length > 0) {
134
+ resolve([{
135
+ path: 'stdin',
136
+ src: stdInData
137
+ }]);
98
138
  } else {
99
- return new Promise(resolve => {
100
- let stdInData = '';
101
- process.stdin.setEncoding('utf8');
102
- process.stdin.on('readable', () => {
103
- const chunk = process.stdin.read();
104
- if (chunk !== null) {
105
- stdInData += chunk;
106
- }
107
- });
108
- process.stdin.on('error', (err) => {
109
- process.exitCode = 1;
110
- console.error(err);
111
- });
112
- process.stdin.on('end', () => {
113
- if (stdInData.length > 0) {
114
- inputFiles.push({
115
- path: 'stdin',
116
- src: stdInData
117
- });
118
- }
119
- resolve(inputFiles);
120
- });
121
- });
139
+ resolve([]);
122
140
  }
123
- })
124
- .then(inputFiles => {
141
+ clearTimeout(waitingTimeout);
142
+ });
143
+ });
144
+
145
+ getFilesFromStdin.then(inputFiles => {
125
146
  const Compiler = require('./lib/node/closure-compiler-js');
147
+ const logErrors = require('./lib/logger');
126
148
  const compiler = new Compiler(compilerFlags);
127
- compiler.run(inputFiles, (exitCode, compiledFiles, errors) => {
128
- if (errors && errors.length > 0) {
129
- console.error(errors);
130
- }
131
- if (compiledFiles.length === 1 && compiledFiles[0].path === 'compiled.js' && !compilerFlags['js_output_file']) {
132
- console.log(compiledFiles[0].src);
149
+ const output = compiler.run(inputFiles);
150
+ if (output.errors.length > 0) {
151
+ process.exitCode = process.exitCode || 1;
152
+ }
153
+ logErrors(output, inputFiles);
154
+ if (output.compiledFiles.length > 0) {
155
+ // If a --js_output_file or --chunk flag was provided, the output should be written to disk
156
+ if (compilerFlags['js_output_file'] || compilerFlags['chunk']) {
157
+ let srcMapPattern = '%outname%.map';
158
+ // Unfortunately the JS version of the compiler supported the `--create_source_map` flag as a boolean.
159
+ // We now support it both as a boolean and as a string path pattern.
160
+ if (compilerFlags.create_source_map && typeof compilerFlags.create_source_map === 'string') {
161
+ srcMapPattern = compilerFlags.create_source_map;
162
+ }
163
+ output.compiledFiles.forEach(compiledFile => {
164
+ mkDirByPathSync(path.dirname(compiledFile.path));
165
+ fs.writeFileSync(compiledFile.path, compiledFile.src, 'utf8');
166
+ if (compiledFile.sourceMap) {
167
+ const srcMapPath = srcMapPattern.replace('%outname%', compiledFile.path);
168
+ mkDirByPathSync(path.dirname(srcMapPath));
169
+ fs.writeFileSync(srcMapPath, compiledFile.sourceMap, 'utf8');
170
+ }
171
+ });
172
+ } else {
173
+ process.stdout.write(`${output.compiledFiles[0].src}\n`);
133
174
  }
134
-
135
- process.exitCode = process.exitCode || exitCode;
136
- });
175
+ }
137
176
  })
138
177
  .catch(e => {
139
178
  console.error(e);
package/compiler.jar CHANGED
Binary file
@@ -30,7 +30,7 @@
30
30
  angular.HttpCallback;
31
31
 
32
32
  /**
33
- * @constructor
33
+ * @interface
34
34
  * @template T
35
35
  */
36
36
  angular.$http.Response = function() {};
@@ -54,7 +54,7 @@ angular.$http.Response.prototype.headers = function(name) {};
54
54
  angular.$http.Response.prototype.config;
55
55
 
56
56
  /**
57
- * @constructor
57
+ * @interface
58
58
  * @extends {angular.$q.Promise.<!angular.$http.Response.<T>>}
59
59
  * @template T
60
60
  */
@@ -28,14 +28,14 @@
28
28
  *****************************************************************************/
29
29
 
30
30
  /**
31
- * @constructor
31
+ * @interface
32
32
  */
33
33
  angular.$q = function() {};
34
34
 
35
35
  /**
36
- * @constructor
36
+ * @interface
37
37
  * @template T
38
- * @implements {IThenable<T>}
38
+ * @extends {IThenable<T>}
39
39
  */
40
40
  angular.$q.Promise = function() {};
41
41
 
@@ -80,7 +80,7 @@ angular.$q.Promise.prototype.finally =
80
80
  function(callback, opt_notifyCallback) {};
81
81
 
82
82
  /**
83
- * @constructor
83
+ * @interface
84
84
  * @template T
85
85
  */
86
86
  angular.$q.Deferred = function() {};
@@ -2373,6 +2373,31 @@ angular.$route.Route.prototype.regexp;
2373
2373
  /** @typedef {function(string):string} */
2374
2374
  angular.$sanitize;
2375
2375
 
2376
+ /******************************************************************************
2377
+ * $sanitizeProvider Service
2378
+ *****************************************************************************/
2379
+
2380
+ /** @interface */
2381
+ angular.$sanitizeProvider = function() {};
2382
+
2383
+ /**
2384
+ * @param {boolean=} enableSvg
2385
+ * @return {boolean|!angular.$sanitizeProvider}
2386
+ */
2387
+ angular.$sanitizeProvider.prototype.enableSvg = function(enableSvg) {};
2388
+
2389
+ /**
2390
+ * @param {!Array<string>|!Object} elements
2391
+ * @return {!angular.$sanitizeProvider}
2392
+ */
2393
+ angular.$sanitizeProvider.prototype.addValidElements = function(elements) {};
2394
+
2395
+ /**
2396
+ * @param {!Array<string>} attrs
2397
+ * @return {!angular.$sanitizeProvider}
2398
+ */
2399
+ angular.$sanitizeProvider.prototype.addValidAttrs = function(attrs) {};
2400
+
2376
2401
  /******************************************************************************
2377
2402
  * $sce Service
2378
2403
  *****************************************************************************/
@@ -1017,6 +1017,7 @@ md.$panel = function() {};
1017
1017
  * onDomRemoved: (Function|undefined),
1018
1018
  * origin: (!angular.JQLite|!Element|undefined),
1019
1019
  * onCloseSuccess: (function(!md.$panel.MdPanelRef, string)|undefined),
1020
+ * groupName: (string|!Array<string>|undefined),
1020
1021
  * }}
1021
1022
  */
1022
1023
  md.$panel.config;
@@ -1039,6 +1040,23 @@ md.$panel.prototype.newPanelPosition = function() {};
1039
1040
  /** @return {!md.$panel.MdPanelAnimation} */
1040
1041
  md.$panel.prototype.newPanelAnimation = function() {};
1041
1042
 
1043
+ /**
1044
+ * @param {string} groupName
1045
+ * @param {{maxOpen: (number|undefined)}=} opt_config
1046
+ * @return {{
1047
+ * panels: !Array<!md.$panel.MdPanelRef>,
1048
+ * openPanels: !Array<!md.$panel.MdPanelRef>,
1049
+ * maxOpen: number,
1050
+ * }}
1051
+ */
1052
+ md.$panel.prototype.newPanelGroup = function(groupName, opt_config) {};
1053
+
1054
+ /**
1055
+ * @param {string} groupName
1056
+ * @param {number} maxOpen
1057
+ */
1058
+ md.$panel.prototype.setGroupMaxOpen = function(groupName, maxOpen) {};
1059
+
1042
1060
  /**
1043
1061
  * Possible values of xPosition.
1044
1062
  * @enum {string}
@@ -1280,3 +1298,15 @@ md.$panel.MdPanelAnimation.prototype.closeTo = function(closeTo) {};
1280
1298
  * @return {!md.$panel.MdPanelAnimation}
1281
1299
  */
1282
1300
  md.$panel.MdPanelAnimation.prototype.withAnimation = function(cssClass) {};
1301
+
1302
+ /******************************************************************************
1303
+ * DatePickerCtrl
1304
+ *****************************************************************************/
1305
+
1306
+ /** @interface */
1307
+ md.DatePickerCtrl = function() {};
1308
+
1309
+ /**
1310
+ * @param {Date=} opt_date
1311
+ */
1312
+ md.DatePickerCtrl.prototype.updateErrorState = function(opt_date) {};
@@ -939,7 +939,8 @@ md.$panel = function() {};
939
939
  * onRemoving: (Function|undefined),
940
940
  * onDomRemoved: (Function|undefined),
941
941
  * origin: (!angular.JQLite|!Element|undefined),
942
- * onCloseSuccess: (function(md.$panel.MdPanelRef, string)|undefined)
942
+ * onCloseSuccess: (function(md.$panel.MdPanelRef, string)|undefined),
943
+ * groupName: (string|!Array<string>|undefined),
943
944
  * }}
944
945
  */
945
946
  md.$panel.config;
@@ -962,6 +963,23 @@ md.$panel.prototype.newPanelPosition = function() {};
962
963
  /** @return {!md.$panel.MdPanelAnimation} */
963
964
  md.$panel.prototype.newPanelAnimation = function() {};
964
965
 
966
+ /**
967
+ * @param {string} groupName
968
+ * @param {{maxOpen: (number|undefined)}=} opt_config
969
+ * @return {{
970
+ * panels: !Array<!md.$panel.MdPanelRef>,
971
+ * openPanels: !Array<!md.$panel.MdPanelRef>,
972
+ * maxOpen: number,
973
+ * }}
974
+ */
975
+ md.$panel.prototype.newPanelGroup = function(groupName, opt_config) {};
976
+
977
+ /**
978
+ * @param {string} groupName
979
+ * @param {number} maxOpen
980
+ */
981
+ md.$panel.prototype.setGroupMaxOpen = function(groupName, maxOpen) {};
982
+
965
983
  /**
966
984
  * Possible values of xPosition.
967
985
  * @enum {string}
@@ -1052,6 +1070,27 @@ md.$panel.MdPanelRef.prototype.removeClass = function(classToRemove) {};
1052
1070
  /** @param {string} classToToggle */
1053
1071
  md.$panel.MdPanelRef.prototype.toggleClass = function(classToToggle) {};
1054
1072
 
1073
+ /**
1074
+ * @param {string} type
1075
+ * @param {function(): !angular.$q.Promise<*>} callback
1076
+ * @return {!md.$panel.MdPanelRef}
1077
+ */
1078
+ md.$panel.MdPanelRef.prototype.registerInterceptor =
1079
+ function(type, callback) {};
1080
+
1081
+ /**
1082
+ * @param {string} type
1083
+ * @param {function(): !angular.$q.Promise<*>} callback
1084
+ * @return {!md.$panel.MdPanelRef}
1085
+ */
1086
+ md.$panel.MdPanelRef.prototype.removeInterceptor = function(type, callback) {};
1087
+
1088
+ /**
1089
+ * @param {string=} opt_type
1090
+ * @return {!md.$panel.MdPanelRef}
1091
+ */
1092
+ md.$panel.MdPanelRef.prototype.removeAllInterceptors = function(opt_type) {};
1093
+
1055
1094
  /**
1056
1095
  * @param {!angular.$window} $window
1057
1096
  * @constructor