bobril-g11n
Advanced tools
Comparing version 5.1.1 to 5.1.2
# CHANGELOG | ||
## 5.1.2 | ||
Slightly improved performance of `RuntimeFunctionGenerator` function. | ||
## 5.1.1 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "bobril-g11n", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "Bobril globalization", | ||
@@ -40,2 +40,2 @@ "main": "index.js", | ||
"license": "MIT" | ||
} | ||
} |
@@ -263,3 +263,3 @@ import * as moment from "moment"; | ||
} else { | ||
comp.addBody(comp.addConstant(compile(locale, item)) + `(${argParams},${argHash})`); | ||
comp.addBody(comp.addConstant(compile(locale, item)), `(${argParams},${argHash})`); | ||
} | ||
@@ -294,3 +294,3 @@ } | ||
} else { | ||
comp.addBody(comp.addConstant(compile(locale, item)) + `(${argParams},${argHash})`); | ||
comp.addBody(comp.addConstant(compile(locale, item)), `(${argParams},${argHash})`); | ||
} | ||
@@ -305,4 +305,4 @@ } | ||
(id: number, valueFactory: (params?: Object, hashArg?: string) => any) => | ||
(params?: Object, hashArg?: string) => | ||
(<any>params)[id](valueFactory(params, hashArg)) | ||
(params?: Object, hashArg?: string) => | ||
(<any>params)[id](valueFactory(params, hashArg)) | ||
)(msgAst.id, compile(locale, msgAst.value)); | ||
@@ -309,0 +309,0 @@ } |
export class RuntimeFunctionGenerator { | ||
constants: any[] = []; | ||
body: string = ''; | ||
body: string[] = []; | ||
argCount: number = 0; | ||
@@ -10,16 +10,16 @@ localCount: number = 0; | ||
for (let i = 0; i < cc.length; i++) { | ||
if (cc[i] === value) return 'c_' + i; | ||
if (cc[i] === value) return "c_" + i; | ||
} | ||
cc.push(value); | ||
return 'c_' + (cc.length - 1); | ||
return "c_" + (cc.length - 1); | ||
} | ||
addArg(index: number): string { | ||
if (index >= this.argCount) this.argCount = index + 1; | ||
return 'a_' + index; | ||
return "a_" + index; | ||
} | ||
addBody(text: string): void { | ||
this.body += text; | ||
addBody(...texts: string[]): void { | ||
([] as string[]).push.apply(this.body, texts); | ||
} | ||
addLocal(): string { | ||
return 'l_' + (this.localCount++); | ||
return "l_" + this.localCount++; | ||
} | ||
@@ -29,3 +29,3 @@ build(): Function { | ||
for (let i = 0; i < this.argCount; i++) { | ||
innerParams.push('a_' + i); | ||
innerParams.push("a_" + i); | ||
} | ||
@@ -35,10 +35,12 @@ if (this.constants.length > 0) { | ||
for (let i = 0; i < this.constants.length; i++) { | ||
params.push('c_' + i); | ||
params.push("c_" + i); | ||
} | ||
params.push('return function(' + innerParams.join(',') + ') {\n' + this.body + '\n}'); | ||
this.body.unshift("return function(", innerParams.join(","), ") {\n"); | ||
this.body.push("\n}"); | ||
params.push(this.body.join("")); | ||
return Function.apply(null, params).apply(null, this.constants); | ||
} | ||
innerParams.push(this.body); | ||
innerParams.push(this.body.join("")); | ||
return Function.apply(null, innerParams); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65293
15
1472