Support
Quality
Security
License
Reuse
kandi has reviewed closure-compiler and discovered the below as its top functions. This is intended to give you an instant insight into closure-compiler implemented functionality, and help decide if they suit your requirements.
Consult the FAQ to make sure that the behaviour you would like isn't specifically excluded (such as string inlining).
Make sure someone hasn't requested the same thing. See the list of known issues.
Read up on what type of feature requests are accepted.
Submit your request as an issue.
Getting Started
yarn global add google-closure-compiler
# OR
npm i -g google-closure-compiler
Basic usage
google-closure-compiler --js file.js --js_output_file file.out.js
NodeJS API
import closureCompiler from 'google-closure-compiler';
const { compiler } = closureCompiler;
new compiler({
js: 'file-one.js',
compilation_level: 'ADVANCED'
});
Compiling Multiple Scripts
google-closure-compiler in1.js in2.js in3.js --js_output_file out.js
Building from a terminal
# bazelisk build //:compiler_unshaded_deploy.jar
yarn build
# bazelisk build :all
yarn build:all
Testing from a terminal
# bazelisk test //:all
Running
# java -jar bazel-bin/compiler_unshaded_deploy.jar [...args]
yarn compile [...args]
JSDoc Mark something as Class after instantiation and define constructor properties
const Queue_PoolEntry = /** @type {QPE_Opts} */ (mongoose.model('Queue_PoolEntry',
Queue_PoolEntrySchema));
let Queue_PoolEntry = mongoose.model('Queue_PoolEntry',
Queue_PoolEntrySchema);
if (Queue_PoolEntry && Queue_PoolEntry.id) {
Queue_PoolEntry = /** @type {QPE_Opts} */ (Queue_PoolEntry)
} else {
throw new Error('mongoose.model(\'Queue_PoolEntry\', Queue_PoolEntrySchema)'+
'returned something other than a QPE_Opts' + Queue_PoolEntry);
}
-----------------------
const Queue_PoolEntry = /** @type {QPE_Opts} */ (mongoose.model('Queue_PoolEntry',
Queue_PoolEntrySchema));
let Queue_PoolEntry = mongoose.model('Queue_PoolEntry',
Queue_PoolEntrySchema);
if (Queue_PoolEntry && Queue_PoolEntry.id) {
Queue_PoolEntry = /** @type {QPE_Opts} */ (Queue_PoolEntry)
} else {
throw new Error('mongoose.model(\'Queue_PoolEntry\', Queue_PoolEntrySchema)'+
'returned something other than a QPE_Opts' + Queue_PoolEntry);
}
How to use use React libraries in ClojureScript
(ns my-project
(:require [cljsjs.vis]))
;; accessing vis via js/WhateverGlobalItUses
(ns my-project
(:require ["vis-network" :as vis]))
;; then use "vis" directly
-----------------------
(ns my-project
(:require [cljsjs.vis]))
;; accessing vis via js/WhateverGlobalItUses
(ns my-project
(:require ["vis-network" :as vis]))
;; then use "vis" directly
Angular 2 example app returns error "Cannot read property 'X' of null"
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "xyz"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"assets/css/styles.css"
],
"scripts": [
"assets/js/project.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
What is the correct jsdoc type annotation for a try..catch identifier?
try {throw new Error();} catch (/** @type {Error}*/whatIsMyType) {
console.error(whatIsMyType.message);
}
try { throw new Error(); } catch (e: Error) {}
try {
throw new CustomError();
}
catch (err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
class CustomError extends Error {
constructor() {
super();
/** @type {string} */
this.aPropThatIndeedExistsInCustomError = '';
throw new Error('Not so fast!'); // The evil part is here
}
}
try {
throw new CustomError();
}
catch (/** @type {CustomError} */err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
-----------------------
try {throw new Error();} catch (/** @type {Error}*/whatIsMyType) {
console.error(whatIsMyType.message);
}
try { throw new Error(); } catch (e: Error) {}
try {
throw new CustomError();
}
catch (err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
class CustomError extends Error {
constructor() {
super();
/** @type {string} */
this.aPropThatIndeedExistsInCustomError = '';
throw new Error('Not so fast!'); // The evil part is here
}
}
try {
throw new CustomError();
}
catch (/** @type {CustomError} */err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
-----------------------
try {throw new Error();} catch (/** @type {Error}*/whatIsMyType) {
console.error(whatIsMyType.message);
}
try { throw new Error(); } catch (e: Error) {}
try {
throw new CustomError();
}
catch (err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
class CustomError extends Error {
constructor() {
super();
/** @type {string} */
this.aPropThatIndeedExistsInCustomError = '';
throw new Error('Not so fast!'); // The evil part is here
}
}
try {
throw new CustomError();
}
catch (/** @type {CustomError} */err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
-----------------------
try {throw new Error();} catch (/** @type {Error}*/whatIsMyType) {
console.error(whatIsMyType.message);
}
try { throw new Error(); } catch (e: Error) {}
try {
throw new CustomError();
}
catch (err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
class CustomError extends Error {
constructor() {
super();
/** @type {string} */
this.aPropThatIndeedExistsInCustomError = '';
throw new Error('Not so fast!'); // The evil part is here
}
}
try {
throw new CustomError();
}
catch (/** @type {CustomError} */err) {
console.log('bing');
if (err instanceof CustomError) {
console.log(err.aPropThatIndeedExistsInCustomError); //works
console.log(err.aPropThatDoesNotExistInCustomError); //error as expected
} else {
console.log(err); // this could still happen
}
}
lein uberjar - not setting main class properly?
:main my.service.runner
ERROR - [JSC_UNDEFINED_VARIABLE] variable previousPage is undeclared - Google Closure Compiler
for (var i = 0; i < individualPagesArray.length; i++) {
document.getElementById("numbers").innerHTML += `<button onclick=showCurrentPage(${i+1})>` + individualPagesArray[i] + `</button>`;
}
window.showCurrentPage = (i) => {
window['showCurrentPage'] = (i) => {
-----------------------
for (var i = 0; i < individualPagesArray.length; i++) {
document.getElementById("numbers").innerHTML += `<button onclick=showCurrentPage(${i+1})>` + individualPagesArray[i] + `</button>`;
}
window.showCurrentPage = (i) => {
window['showCurrentPage'] = (i) => {
-----------------------
for (var i = 0; i < individualPagesArray.length; i++) {
document.getElementById("numbers").innerHTML += `<button onclick=showCurrentPage(${i+1})>` + individualPagesArray[i] + `</button>`;
}
window.showCurrentPage = (i) => {
window['showCurrentPage'] = (i) => {
strange object property behavior with closure compiler ADVANCED_OPTIMIZATIONS
/**
* @interface
*/
function AppProps() {}
/**
* @type {string}
*/
AppProps.prototype.version;
/**
* @type {string}
*/
AppProps.prototype.api_host;
/**
*
* @param {AppProps} props
*/
window['app'] = function(props) {
props = props || {};
console.log("props.api_host = ", props.api_host);
console.log("props['api_host'] = ", props['api_host']);
};
-----------------------
/**
* @interface
*/
function AppProps() {}
/**
* @type {string}
*/
AppProps.prototype.version;
/**
* @type {string}
*/
AppProps.prototype.api_host;
/**
*
* @param {AppProps} props
*/
window['app'] = function(props) {
props = props || {};
console.log("props.api_host = ", props.api_host);
console.log("props['api_host'] = ", props['api_host']);
};
google-closure-compiler basic process example
const ClosureCompiler = require('google-closure-compiler').jsCompiler;
const {writeFile, readFileSync} = require('fs');
const closureCompiler = new ClosureCompiler({
compilation_level: 'ADVANCED'
});
let src = readFileSync('a.js', 'UTF-8');
const compilerProcess = closureCompiler.run([{
path: './',
src: src,
sourceMap: null
}], (exitCode, stdOut, stdErr) => {
stdOut.map((fileResults) => {
writeFile(fileResults.path, fileResults.src, () => {});
});
});
console.log('hello world!')
console.log("hello world!");
-----------------------
const ClosureCompiler = require('google-closure-compiler').jsCompiler;
const {writeFile, readFileSync} = require('fs');
const closureCompiler = new ClosureCompiler({
compilation_level: 'ADVANCED'
});
let src = readFileSync('a.js', 'UTF-8');
const compilerProcess = closureCompiler.run([{
path: './',
src: src,
sourceMap: null
}], (exitCode, stdOut, stdErr) => {
stdOut.map((fileResults) => {
writeFile(fileResults.path, fileResults.src, () => {});
});
});
console.log('hello world!')
console.log("hello world!");
-----------------------
const ClosureCompiler = require('google-closure-compiler').jsCompiler;
const {writeFile, readFileSync} = require('fs');
const closureCompiler = new ClosureCompiler({
compilation_level: 'ADVANCED'
});
let src = readFileSync('a.js', 'UTF-8');
const compilerProcess = closureCompiler.run([{
path: './',
src: src,
sourceMap: null
}], (exitCode, stdOut, stdErr) => {
stdOut.map((fileResults) => {
writeFile(fileResults.path, fileResults.src, () => {});
});
});
console.log('hello world!')
console.log("hello world!");
-----------------------
const ClosureCompiler = require('google-closure-compiler').jsCompiler;
const { writeFile } = require('fs');
const closureCompiler = new ClosureCompiler({
js:['a.js','a1.js'],
js_output_file: 'out.js'
});
const compilerProcess = closureCompiler.run([{
path: './',
}], (exitCode, stdOut, stdErr) => {
writeFile(stdOut[0].path, stdOut[0].src,()=>{});
});
command line compiling generates bigger file than the online version
--language_out=ECMASCRIPT_2015
Clojure + Clojurescript app on Heroku: dependencies of npm packages not getting installed when deploying app
FROM openjdk:8-alpine
COPY target/uberjar/getfluentspanish.jar /getfluentspanish/app.jar
EXPOSE 3000
CMD ["java", "-jar", "/getfluentspanish/app.jar"]
QUESTION
JSDoc Mark something as Class after instantiation and define constructor properties
Asked 2020-Aug-27 at 15:09I have mongoose create a Model(class) for me, and I would like to have the class to have intellisense. The problem is I don't know how to mark something as a class, and how to type the constructor for that class.
Looking at JSDocs' docs they only specify how to type a class at the declaration, not when it already has been instantiated. The @class
and @constructor
tags don't seem to do anything.
Right now I am getting my intellisense by marking it as a function (which it is under the hood, but it would still be great to have the correct colors in VSC) and defining the params:
/**
* @typedef QPE_Opts
* @type {object}
* @prop {string} id - Id of the user
* ...
*/
/**
* @type {function(QPE_Opts) : mongoose.Model<mongoose.Document, {}> }}
*/
const Queue_PoolEntry = mongoose.model('Queue_PoolEntry', Queue_PoolEntrySchema);
The solution (Was looking at the JsDocs' Documentation which was not providing enough info, thanks @Graham P Heath for giving the better docs) :
/**
* @type {function(new:mongoose.Model<mongoose.Document, {}>, QPE_Opts ) }}
*/
ANSWER
Answered 2020-Aug-26 at 14:49If you are sure of the type of an object you can type cast it:
const Queue_PoolEntry = /** @type {QPE_Opts} */ (mongoose.model('Queue_PoolEntry',
Queue_PoolEntrySchema));
In situations where you can't actually be sure of the returned type casting may be a code smell. In that case: use code to determine the validity of your type assertion by checking the object for expected properties, and only then casting it.
let Queue_PoolEntry = mongoose.model('Queue_PoolEntry',
Queue_PoolEntrySchema);
if (Queue_PoolEntry && Queue_PoolEntry.id) {
Queue_PoolEntry = /** @type {QPE_Opts} */ (Queue_PoolEntry)
} else {
throw new Error('mongoose.model(\'Queue_PoolEntry\', Queue_PoolEntrySchema)'+
'returned something other than a QPE_Opts' + Queue_PoolEntry);
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit