X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/angular2/src/compiler/html_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class HtmlAttrAst implements HtmlAst {

export class HtmlElementAst implements HtmlAst {
constructor(public name: string, public attrs: HtmlAttrAst[], public children: HtmlAst[],
public sourceSpan: ParseSourceSpan) {}
public sourceSpan: ParseSourceSpan, public startSourceSpan: ParseSourceSpan,
public endSourceSpan: ParseSourceSpan) {}
visit(visitor: HtmlAstVisitor, context: any): any { return visitor.visitElement(this, context); }
}

Expand Down
10 changes: 7 additions & 3 deletions modules/angular2/src/compiler/html_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ class TreeBuilder {
selfClosing = false;
}
var end = this.peek.sourceSpan.start;
var el = new HtmlElementAst(fullName, attrs, [],
new ParseSourceSpan(startTagToken.sourceSpan.start, end));
let span = new ParseSourceSpan(startTagToken.sourceSpan.start, end);
var el = new HtmlElementAst(fullName, attrs, [], span, span, null);
this._pushElement(el);
if (selfClosing) {
this._popElement(fullName);
el.endSourceSpan = span;
}
}

Expand All @@ -173,7 +174,8 @@ class TreeBuilder {
var tagDef = getHtmlTagDefinition(el.name);
var parentEl = this._getParentElement();
if (tagDef.requireExtraParent(isPresent(parentEl) ? parentEl.name : null)) {
var newParent = new HtmlElementAst(tagDef.parentToAdd, [], [el], el.sourceSpan);
var newParent = new HtmlElementAst(tagDef.parentToAdd, [], [el], el.sourceSpan,
el.startSourceSpan, el.endSourceSpan);
this._addToParent(newParent);
this.elementStack.push(newParent);
this.elementStack.push(el);
Expand All @@ -187,6 +189,8 @@ class TreeBuilder {
var fullName =
getElementFullName(endTagToken.parts[0], endTagToken.parts[1], this._getParentElement());

this._getParentElement().endSourceSpan = endTagToken.sourceSpan;

if (getHtmlTagDefinition(fullName).isVoid) {
this.errors.push(
HtmlTreeError.create(fullName, endTagToken.sourceSpan,
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/compiler/legacy_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class LegacyHtmlAstTransformer implements HtmlAstVisitor {
this.visitingTemplateEl = ast.name.toLowerCase() == 'template';
let attrs = ast.attrs.map(attr => attr.visit(this, null));
let children = ast.children.map(child => child.visit(this, null));
return new HtmlElementAst(ast.name, attrs, children, ast.sourceSpan);
return new HtmlElementAst(ast.name, attrs, children, ast.sourceSpan, ast.startSourceSpan,
ast.endSourceSpan);
}

visitAttr(originalAst: HtmlAttrAst, context: any): HtmlAttrAst {
Expand Down
25 changes: 21 additions & 4 deletions modules/angular2/src/core/change_detection/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class ParseException extends BaseException {
}
}

export class SplitInterpolation {
constructor(public strings: string[], public expressions: string[]) {}
}

@Injectable()
export class Parser {
/** @internal */
Expand Down Expand Up @@ -118,6 +122,21 @@ export class Parser {
}

parseInterpolation(input: string, location: any): ASTWithSource {
let split = this.splitInterpolation(input, location);
if (split == null) return null;

let expressions = [];

for (let i = 0; i < split.expressions.length; ++i) {
var tokens = this._lexer.tokenize(split.expressions[i]);
var ast = new _ParseAST(input, location, tokens, this._reflector, false).parseChain();
expressions.push(ast);
}

return new ASTWithSource(new Interpolation(split.strings, expressions), input, location);
}

splitInterpolation(input: string, location: string): SplitInterpolation {
var parts = StringWrapper.split(input, INTERPOLATION_REGEXP);
if (parts.length <= 1) {
return null;
Expand All @@ -131,16 +150,14 @@ export class Parser {
// fixed string
strings.push(part);
} else if (part.trim().length > 0) {
var tokens = this._lexer.tokenize(part);
var ast = new _ParseAST(input, location, tokens, this._reflector, false).parseChain();
expressions.push(ast);
expressions.push(part);
} else {
throw new ParseException('Blank expressions are not allowed in interpolated strings', input,
`at column ${this._findInterpolationErrorColumn(parts, i)} in`,
location);
}
}
return new ASTWithSource(new Interpolation(strings, expressions), input, location);
return new SplitInterpolation(strings, expressions);
}

wrapLiteralPrimitive(input: string, location: any): ASTWithSource {
Expand Down
8 changes: 8 additions & 0 deletions modules/angular2/src/facade/collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ class ListWrapper {
static bool isImmutable(List l) {
return l is UnmodifiableListView;
}

static List flatten(List l) {
final res = [];
l.forEach((item) {
res.addAll(item);
});
return res;
}
}

bool isListLikeIterable(obj) => obj is Iterable;
Expand Down
5 changes: 5 additions & 0 deletions modules/angular2/src/facade/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ export class ListWrapper {
}

static isImmutable(list: any[]): boolean { return Object.isSealed(list); }
static flatten<T>(array: T[][]): T[] {
let res = [];
array.forEach((a) => res = res.concat(a));
return res;
}
}

export function isListLikeIterable(obj: any): boolean {
Expand Down
14 changes: 14 additions & 0 deletions modules/angular2/src/facade/lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ class RegExpWrapper {
static Iterator<Match> matcher(RegExp regExp, String input) {
return regExp.allMatches(input).iterator;
}

static String replaceAll(RegExp regExp, String input, Function replace) {
final m = RegExpWrapper.matcher(regExp, input);
var res = "";
var prev = 0;
while(m.moveNext()) {
var c = m.current;
res += input.substring(prev, c.start);
res += replace(c);
prev = c.start + c[0].length;
}
res += input.substring(prev);
return res;
}
}

class RegExpMatcherWrapper {
Expand Down
15 changes: 15 additions & 0 deletions modules/angular2/src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@ export class RegExpWrapper {
regExp.lastIndex = 0;
return {re: regExp, input: input};
}
static replaceAll(regExp: RegExp, input: string, replace: Function): string {
let c = regExp.exec(input);
let res = '';
regExp.lastIndex = 0;
let prev = 0;
while (c) {
res += input.substring(prev, c.index);
res += replace(c);
prev = c.index + c[0].length;
regExp.lastIndex = prev;
c = regExp.exec(input);
}
res += input.substring(prev);
return res;
}
}

export class RegExpMatcherWrapper {
Expand Down
Loading
X Tutup