| Index: tool/patch_sdk.dart
|
| diff --git a/tool/patch_sdk.dart b/tool/patch_sdk.dart
|
| index d3c507b58f3b09472060c722c6579fd1e73ed4b4..1324d41193b85bc8b4df04964ead7280b8f4e693 100755
|
| --- a/tool/patch_sdk.dart
|
| +++ b/tool/patch_sdk.dart
|
| @@ -159,21 +159,34 @@ 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);
|
| +
|
| + // To patch a library, we must have a library directive
|
| + var libDir = unit.directives.first as LibraryDirective;
|
| + int importPos = unit.directives.lastWhere((d) => d is ImportDirective,
|
| + orElse: () => libDir).end;
|
| + for (var d in patch.unit.directives.where((d) => d is ImportDirective)) {
|
| + _merge(d, importPos);
|
| + }
|
| +
|
| + int partPos = unit.directives.last.end;
|
| + 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);
|
| }
|
| }
|
|
|
|
|