@atjson/renderer-hir
Advanced tools
Comparing version 0.5.17 to 0.5.18
@@ -5,4 +5,4 @@ "use strict"; | ||
const hir_1 = require("@atjson/hir"); | ||
function compile(scope, node) { | ||
let generator = scope.invoke(scope.renderAnnotation, node); | ||
function compile(renderer, node, state) { | ||
let generator = renderer.renderAnnotation(node, state); | ||
let result = generator.next(); | ||
@@ -17,29 +17,35 @@ if (result.done) { | ||
else { | ||
return compile(scope, childNode); | ||
return compile(renderer, childNode, state); | ||
} | ||
})).value; | ||
} | ||
class Renderer { | ||
class State { | ||
constructor() { | ||
this.scopes = []; | ||
this._state = []; | ||
} | ||
pushScope(scope) { | ||
this.scopes.push(Object.assign({ | ||
popScope: () => this.popScope(), | ||
pushScope: (pushedScope) => this.pushScope(pushedScope) | ||
}, scope)); | ||
push(list) { | ||
this._state.push(list); | ||
} | ||
popScope() { | ||
this.scopes.pop(); | ||
pop() { | ||
this._state.pop(); | ||
} | ||
invoke(fn, ...args) { | ||
let scope = this.scopes[this.scopes.length - 1]; | ||
return fn.call(scope, ...args); | ||
get(key) { | ||
let currentState = this._state[this._state.length - 1]; | ||
if (currentState) { | ||
return currentState[key]; | ||
} | ||
return null; | ||
} | ||
willRender() { | ||
this.pushScope({}); | ||
set(key, value) { | ||
let currentState = this._state[this._state.length - 1]; | ||
if (currentState) { | ||
currentState[key] = value; | ||
} | ||
else { | ||
this.push({ [key]: value }); | ||
} | ||
} | ||
didRender() { | ||
this.popScope(); | ||
} | ||
} | ||
exports.State = State; | ||
class Renderer { | ||
render(atjson) { | ||
@@ -56,5 +62,4 @@ let annotationGraph; | ||
} | ||
this.willRender(); | ||
let renderedDocument = compile(this, annotationGraph.rootNode); | ||
this.didRender(); | ||
let state = new State(); | ||
let renderedDocument = compile(this, annotationGraph.rootNode, state); | ||
return renderedDocument; | ||
@@ -64,2 +69,2 @@ } | ||
exports.default = Renderer; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanM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QUFqQkQsMkJBaUJDIn0= |
"use strict"; | ||
import { AtJSON } from '@atjson/core'; | ||
import { HIR } from '@atjson/hir'; | ||
function compile(scope, node) { | ||
let generator = scope.invoke(scope.renderAnnotation, node); | ||
function compile(renderer, node, state) { | ||
let generator = renderer.renderAnnotation(node, state); | ||
let result = generator.next(); | ||
@@ -15,29 +15,34 @@ if (result.done) { | ||
else { | ||
return compile(scope, childNode); | ||
return compile(renderer, childNode, state); | ||
} | ||
})).value; | ||
} | ||
export default class Renderer { | ||
export class State { | ||
constructor() { | ||
this.scopes = []; | ||
this._state = []; | ||
} | ||
pushScope(scope) { | ||
this.scopes.push(Object.assign({ | ||
popScope: () => this.popScope(), | ||
pushScope: (pushedScope) => this.pushScope(pushedScope) | ||
}, scope)); | ||
push(list) { | ||
this._state.push(list); | ||
} | ||
popScope() { | ||
this.scopes.pop(); | ||
pop() { | ||
this._state.pop(); | ||
} | ||
invoke(fn, ...args) { | ||
let scope = this.scopes[this.scopes.length - 1]; | ||
return fn.call(scope, ...args); | ||
get(key) { | ||
let currentState = this._state[this._state.length - 1]; | ||
if (currentState) { | ||
return currentState[key]; | ||
} | ||
return null; | ||
} | ||
willRender() { | ||
this.pushScope({}); | ||
set(key, value) { | ||
let currentState = this._state[this._state.length - 1]; | ||
if (currentState) { | ||
currentState[key] = value; | ||
} | ||
else { | ||
this.push({ [key]: value }); | ||
} | ||
} | ||
didRender() { | ||
this.popScope(); | ||
} | ||
} | ||
export default class Renderer { | ||
render(atjson) { | ||
@@ -54,8 +59,7 @@ let annotationGraph; | ||
} | ||
this.willRender(); | ||
let renderedDocument = compile(this, annotationGraph.rootNode); | ||
this.didRender(); | ||
let state = new State(); | ||
let renderedDocument = compile(this, annotationGraph.rootNode, state); | ||
return renderedDocument; | ||
} | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9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VBQUUsS0FBSyxDQUFDLENBQUM7UUFDdEUsTUFBTSxDQUFDLGdCQUFnQixDQUFDO0lBQzFCLENBQUM7Q0FDRiJ9 |
{ | ||
"name": "@atjson/renderer-hir", | ||
"version": "0.5.17", | ||
"version": "0.5.18", | ||
"description": "A brand new TypeScript library.", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/index.js", |
import { AtJSON } from '@atjson/core'; | ||
import { HIR, HIRNode } from '@atjson/hir'; | ||
function compile(scope: Renderer, node: HIRNode): any { | ||
let generator = scope.invoke(scope.renderAnnotation, node); | ||
function compile(renderer: Renderer, node: HIRNode, state: State): any { | ||
let generator = renderer.renderAnnotation(node, state); | ||
let result = generator.next(); | ||
@@ -15,3 +15,3 @@ if (result.done) { | ||
} else { | ||
return compile(scope, childNode); | ||
return compile(renderer, childNode, state); | ||
} | ||
@@ -21,37 +21,43 @@ })).value; | ||
export default abstract class Renderer { | ||
private scopes: object[]; | ||
interface StateList { | ||
[key: string]: value: any; | ||
} | ||
export class State { | ||
private _state: StateList[]; | ||
constructor() { | ||
this.scopes = []; | ||
this._state = []; | ||
} | ||
pushScope(scope: any): void { | ||
this.scopes.push(Object.assign({ | ||
popScope: () => this.popScope(), | ||
pushScope: (pushedScope: any) => this.pushScope(pushedScope) | ||
}, scope)); | ||
push(list: StateList) { | ||
this._state.push(list); | ||
} | ||
popScope(): void { | ||
this.scopes.pop(); | ||
pop() { | ||
this._state.pop(); | ||
} | ||
invoke(fn: (node: HIRNode) => IterableIterator<string>, ...args: any[]) { | ||
let scope = this.scopes[this.scopes.length - 1]; | ||
return fn.call(scope, ...args); | ||
get(key: string): any { | ||
let currentState: StateList | null = this._state[this._state.length - 1]; | ||
if (currentState) { | ||
return currentState[key]; | ||
} | ||
return null; | ||
} | ||
abstract renderAnnotation(node: HIRNode): IterableIterator<any>; | ||
willRender(): void { | ||
this.pushScope({}); | ||
set(key: string, value: any) { | ||
let currentState: StateList | null = this._state[this._state.length - 1]; | ||
if (currentState) { | ||
currentState[key] = value; | ||
} else { | ||
this.push({ [key]: value }); | ||
} | ||
} | ||
} | ||
didRender(): void { | ||
this.popScope(); | ||
} | ||
export default abstract class Renderer { | ||
abstract renderAnnotation(node: HIRNode, state: State): IterableIterator<any>; | ||
render(atjson: AtJSON | HIR): any { | ||
let annotationGraph; | ||
@@ -66,7 +72,6 @@ if (atjson instanceof AtJSON) { | ||
this.willRender(); | ||
let renderedDocument = compile(this, annotationGraph.rootNode); | ||
this.didRender(); | ||
let state = new State(); | ||
let renderedDocument = compile(this, annotationGraph.rootNode, state); | ||
return renderedDocument; | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
11576
5
189
1