add oldName(...) annotation for automatic renaming of APIs
This commit is contained in:
Родитель
dd380a3f67
Коммит
e06aad3927
15
ast/api.ts
15
ast/api.ts
|
@ -1446,6 +1446,21 @@ module TDev {
|
|||
if (!this._imports) this._imports = [];
|
||||
this._imports.push({ manager: manager, name: name, version: version });
|
||||
}
|
||||
public md_oldName(s:string) {
|
||||
var pref = this.parentKind.getName() + "->"
|
||||
if (/->/.test(s))
|
||||
s = Util.capitalizeFirst(s)
|
||||
else
|
||||
s = pref + s
|
||||
if (Util.startsWith(s, pref))
|
||||
AST.propRenames[s] = this.getName()
|
||||
else {
|
||||
var m = /(.*)->(.*)/.exec(s)
|
||||
var k = api.getKind(m[1])
|
||||
if (!k) this.md_oops("no such kind: " + m[1])
|
||||
AST.crossKindRenames[k.getName().toLowerCase() + "->" + m[2]] = this.parentKind.getName().toLowerCase() + "->" + this.getName()
|
||||
}
|
||||
}
|
||||
public getImports() { return this._imports; }
|
||||
|
||||
private md_oops(msg:string)
|
||||
|
|
|
@ -20,6 +20,9 @@ module TDev.AST {
|
|||
export var blockMode = false;
|
||||
export var legacyMode = true;
|
||||
|
||||
export var propRenames:StringMap<string> = {};
|
||||
export var crossKindRenames:StringMap<string> = {};
|
||||
|
||||
export function reset()
|
||||
{
|
||||
currentNodeId = 1;
|
||||
|
|
|
@ -318,6 +318,21 @@ module TDev.AST
|
|||
}
|
||||
|
||||
expr.clearError();
|
||||
|
||||
expr.tokens.forEach((t, i) => {
|
||||
if (!(t instanceof ThingRef)) return
|
||||
var tt = <ThingRef>t
|
||||
if (tt.forceLocal) return
|
||||
if (!(expr.tokens[i + 1] instanceof PropertyRef)) return
|
||||
var pp = <PropertyRef>expr.tokens[i + 1]
|
||||
var key = tt.data + "->" + pp.data
|
||||
if (AST.crossKindRenames.hasOwnProperty(key)) {
|
||||
var m = /(.*)->(.*)/.exec(AST.crossKindRenames[key])
|
||||
tt.data = m[1]
|
||||
pp.data = m[2]
|
||||
}
|
||||
})
|
||||
|
||||
var parsed = ExprParser.parse1(expr.tokens);
|
||||
parsed.clearError();
|
||||
parsed._kind = null;
|
||||
|
@ -1819,6 +1834,13 @@ module TDev.AST
|
|||
}
|
||||
}
|
||||
|
||||
if (!prop) {
|
||||
var pref = k0.getName() + "->"
|
||||
var autoRenameKey = pref + t.propRef.data
|
||||
if (AST.propRenames.hasOwnProperty(autoRenameKey))
|
||||
prop = k0.getProperty(AST.propRenames[autoRenameKey])
|
||||
}
|
||||
|
||||
if (!prop) {
|
||||
if (prevErr == this.errorCount)
|
||||
this.markError(t, lf("TD112: i cannot find property '{0}' on {1}", t.propRef.data, k0));
|
||||
|
|
|
@ -402,6 +402,7 @@ module TDev.RT {
|
|||
export var DEBUG = 7;
|
||||
|
||||
//? Appends this message to the debug log.
|
||||
//@ oldName("time->log")
|
||||
export function log(message: string): void
|
||||
{
|
||||
logEvent(INFO, "", message, undefined);
|
||||
|
|
|
@ -31,7 +31,7 @@ module TDev.RT {
|
|||
|
||||
//? Returns a random integral number bounded between limit and 0, not including limit unless it is 0
|
||||
//@ tandre
|
||||
//@ [limit].defl(2)
|
||||
//@ [limit].defl(2) oldName("rand")
|
||||
export function random(limit: number): number {
|
||||
var max = Math.round(limit);
|
||||
if (max == 0) return 0;
|
||||
|
@ -45,11 +45,6 @@ module TDev.RT {
|
|||
//@ tandre
|
||||
export function random_normalized() : number { return Random.normalized(); }
|
||||
|
||||
//? Renamed to 'random'
|
||||
//@ hidden
|
||||
//@ tandre
|
||||
export function rand(max:number) : number { return random(max); }
|
||||
|
||||
//? Renamed to 'random normalized'
|
||||
//@ hidden
|
||||
//@ tandre
|
||||
|
|
|
@ -36,7 +36,7 @@ module TDev.RT {
|
|||
//? Gets a random picture; invalid if collection is empty
|
||||
//@ returns(Picture) picAsync
|
||||
public random(r : ResumeCtx) {
|
||||
this.at(Math_.rand(this.count()), r);
|
||||
this.at(Math_.random(this.count()), r);
|
||||
}
|
||||
|
||||
//? Gets the number of elements in the collection
|
||||
|
|
Загрузка…
Ссылка в новой задаче