google-closure-compiler

Type Checking Array Contents with Closure-Compiler

十年热恋 提交于 2019-12-10 13:14:18
问题 In Google Closure, if an Array of a specific @type {Array.<type>} is initialized, can I be sure that Google Closure will confirm the Array contents? Here is a small test case. It appears to me that an {Array.<string>} is sneaking past an {Array.<number>} check, although a {string} is correctly blocked by the same check. I am a little new to GC, is this an error on my part? I've pasted this to the Google Closure Service, and I'm showing only one of two expected errors (Sept 12 2013). I've

What syntax I should use to declare externs for closure compiler?

独自空忆成欢 提交于 2019-12-10 12:10:26
问题 I want to declare some externs for closure compiler but not know how to do it? (function(window) { window.myapi = window.myapi || {}; var myapi = window.myapi; myapi.hello = function() { window.document.write('Hello'); } }(window)); I am not sure how to do it for window.myapi, window.myapi.hello? 回答1: Externs are valid javascript, but they are just type information. They should not contain definitions (or for functions only empty definitions). Here's a start: How to Write Closure-compiler

Javascript Module pattern, Prototype and Google Closure

谁说胖子不能爱 提交于 2019-12-10 10:59:50
问题 I am having trouble getting this code structure to survive obfuscation with the Google Closure Compiler. Here's some sample code: var MyModule = (function() { function myModule() { // Constructor } function moduleFoo(url) { // Method } function moduleBar() { // Method } myModule.prototype = { constructor: myModule, foo: moduleFoo, bar: moduleBar }; return myModule; })(); Elsewhere in my code I need be able to write things like the following: var myMod = new MyModule(); myMod.foo(); myMod.bar(

Adding sub-properties to an existing property-list in jsdoc

送分小仙女□ 提交于 2019-12-10 09:23:13
问题 I am trying to automate a particular module in our JS library and am stuck at a point where I want to define a set of properties (lets say an object that goes as construction parameter of a class). /** * This function initiates world peace! * @constructor * @param {object} defaults - The options to initiate peace. * @param {number} defaults.issues - The number of issues being taken up. * @param {string} defaults.source - The name of the location where process starts. */ var WorldPeace =

Using Google Closure's @typedef tag

五迷三道 提交于 2019-12-10 04:22:51
问题 Google's Closure compiler has an "@typedef" tag, but is it OK to use them in your code? (I know it'll work, but is it frowned upon?) So here's my type /** * The plan object's typedef * @typedef {Object} */ Types.Plan = { "style": "bordersmall", "width": "50%", "height": "40%", "x": "20%", "y": "10%", "clickable": true, "moveable": true }; And then I can use that type in my JSDoc annotations. This allows my IDE to give me autocomplete on the passed parameter So the declared object isn't used

What does “WARNING - Suspicious code. The result of the 'getprop' operator is not being used.” mean?

☆樱花仙子☆ 提交于 2019-12-08 16:45:56
问题 "WARNING - Suspicious code. The result of the 'getprop' operator is not being used." I'm seeing this for two lines in my JavaScript code when I use the closure compiler. They are typedefs in among other typedefs that don't report issues. What should I be looking for? EDIT Affected code: /** * @typedef {{playerId: number, playerName: string, baseScores: Array.<number>, bonusScores: Array.<number>, * teamScoreAdjustments: Array.<number>}} */ wias.GameTableTeamMember; /** * @typedef {{id: number

Closure Compiler issues warning with namespaced enum

折月煮酒 提交于 2019-12-07 16:19:37
问题 The following sample code generates a compiler warning on advanced optimization: "JSC_UNSAFE_NAMESPACE: incomplete alias created for namespace NS". If I remove the @enum comment, it doesn't give the warning. var NS = {}; /** * @enum {string} */ NS.type = { FOO : 'bar' }; NS.foobar = function(){ alert(NS.type.FOO); }; window['NS'] = NS; window['NS']['foobar'] = NS.foobar; Exporting only the function and not the namespace also seems to work: window['NS_foobar'] = NS.foobar; What am I doing

Google Closure Compiler and multipart/form-data not working

谁说胖子不能爱 提交于 2019-12-07 11:25:59
问题 I'm making a request to the google closure compiler API service: $content = file_get_contents('file.js'); $url = 'http://closure-compiler.appspot.com/compile'; $post = true; $postData = array('output_info' => 'compiled_code', 'output_format' => 'text', 'compilation_level' => 'SIMPLE_OPTIMIZATIONS', 'js_code' => urlencode($content))); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if ($post) { curl

Why is Google Closure Compiler failing on my ES6 object which extends Date()?

蓝咒 提交于 2019-12-07 10:45:07
问题 Please note: this question relates to the use of Google's Closure Compiler. It's not directly about ES6, since that part is working. I've written a class in ES6 which extends the native Date object. It's a large class, but this is a simplified version: class Dative extends Date { constructor (dateData) { super(); super.setTime(Date.parse(dateData)); } addMilliseconds (ms) { super.setTime(super.getTime() + ms); } } The code above works fine in Chrome and Firefox. However, when I pass it

ngInject and closure compiler

ε祈祈猫儿з 提交于 2019-12-07 09:02:51
问题 I try to compile the following code in ADVANCED mode unsuccessfully: /** * @description App configuration * @param {!angular.$routeProvider} $routeProvider * @constructor * @ngInject */ function Config ($routeProvider) { $routeProvider .when('/', { templateUrl: 'mainpage/mainpage.html', controller: 'MainpageCtrl' }) .when('/viewer', { templateUrl: 'viewer/viewer.html', controller: 'ViewerCtrl' }) .otherwise({ redirectTo: '/' }); } Is there any special flag to be turned on? If I add the