Chromium Code Reviews| Index: tool/patch_sdk.dart |
| diff --git a/tool/patch_sdk.dart b/tool/patch_sdk.dart |
| index d3c507b58f3b09472060c722c6579fd1e73ed4b4..3a2262fa56a6c249dc9fe3b0fde09e7d9ac6499d 100755 |
| --- a/tool/patch_sdk.dart |
| +++ b/tool/patch_sdk.dart |
| @@ -159,21 +159,33 @@ class PatchApplier extends GeneralizingAstVisitor { |
| if (_isLibrary) _mergeUnpatched(node); |
| } |
| + void _merge(AstNode node, int pos) { |
| + var code = patch.contents.substring(node.offset, node.end); |
| + edits.insert(pos, '\n' + code); |
| + } |
| + |
| /// Merges directives and declarations that are not `@patch` into the library. |
| void _mergeUnpatched(CompilationUnit unit) { |
| - // Merge directives from the patch |
| + |
| + // Merge imports from the patch |
| // TODO(jmesserly): remove duplicate imports |
| - var directivePos = unit.directives.last.end; |
| - for (var directive in patch.unit.directives) { |
| - var code = patch.contents.substring(directive.offset, directive.end); |
| - edits.insert(directivePos, '\n' + code); |
| + |
| + int partPos = unit.directives.last.end; |
|
Leaf
2015/04/23 21:32:55
I think directives can be null if there are no dir
Jennifer Messerly
2015/04/23 21:44:28
maybe, yeah. That can only happen for "scripts" th
|
| + var lastImport = unit.directives.lastWhere((d) => d is ImportDirective, |
| + orElse: () => null); |
| + int importPos = lastImport != null ? lastImport.end : partPos; |
|
Leaf
2015/04/23 21:32:55
Doesn't this still put the new imports after the p
Jennifer Messerly
2015/04/23 21:44:28
Good catch! I'll have it go after the library dire
|
| + |
| + for (var d in patch.unit.directives.where((d) => d is ImportDirective)) { |
| + _merge(d, importPos); |
| + } |
| + for (var d in patch.unit.directives.where((d) => d is PartDirective)) { |
| + _merge(d, partPos); |
| } |
| // Merge declarations from the patch |
| - var declarationPos = edits.original.length; |
| - for (var declaration in patch.mergeDeclarations) { |
| - var code = patch.contents.substring(declaration.offset, declaration.end); |
| - edits.insert(declarationPos, '\n' + code); |
| + int declPos = edits.original.length; |
| + for (var d in patch.mergeDeclarations) { |
| + _merge(d, declPos); |
| } |
| } |