mirror of
https://github.com/angular/angular.git
synced 2026-11-28 17:37:50 -05:00
feat(dart/transform): Support part directives
Allow users to split libraries using the `part` directive. Closes #1817
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
library angular2.src.core.compiler.directive_lifecycle_reflector;
|
||||
|
||||
import 'package:angular2/src/core/annotations_impl/annotations.dart';
|
||||
import 'package:angular2/src/core/compiler/interfaces.dart';
|
||||
import 'package:angular2/src/reflection/reflection.dart';
|
||||
|
||||
@@ -100,7 +100,8 @@ class Expect extends gns.Expect {
|
||||
void toThrowError([message = ""]) => toThrowWith(message: message);
|
||||
void toThrowErrorWith(message) => expectException(this.actual, message);
|
||||
void toBePromise() => gns.guinness.matchers.toBeTrue(actual is Future);
|
||||
void toHaveCssClass(className) => gns.guinness.matchers.toBeTrue(DOM.hasClass(actual, className));
|
||||
void toHaveCssClass(className) =>
|
||||
gns.guinness.matchers.toBeTrue(DOM.hasClass(actual, className));
|
||||
void toImplement(expected) => toBeA(expected);
|
||||
void toBeNaN() =>
|
||||
gns.guinness.matchers.toBeTrue(double.NAN.compareTo(actual) == 0);
|
||||
@@ -139,7 +140,8 @@ class NotExpect extends gns.NotExpect {
|
||||
|
||||
void toEqual(expected) => toHaveSameProps(expected);
|
||||
void toBePromise() => gns.guinness.matchers.toBeFalse(actual is Future);
|
||||
void toHaveCssClass(className) => gns.guinness.matchers.toBeFalse(DOM.hasClass(actual, className));
|
||||
void toHaveCssClass(className) =>
|
||||
gns.guinness.matchers.toBeFalse(DOM.hasClass(actual, className));
|
||||
void toBeNull() => gns.guinness.matchers.toBeFalse(actual == null);
|
||||
Function get _expect => gns.guinness.matchers.expect;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class AsyncStringWriter extends PrintWriter {
|
||||
: _curr = curr,
|
||||
_bufs = <StringBuffer>[curr];
|
||||
|
||||
AsyncStringWriter() : this._(new StringBuffer());
|
||||
AsyncStringWriter([Object content = ""]) : this._(new StringBuffer(content));
|
||||
|
||||
void print(x) {
|
||||
_curr.write(x);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -95,7 +95,8 @@ Map<String, dynamic> serializeKeyboardEvent(dynamic e) {
|
||||
}
|
||||
|
||||
// TODO(jteplitz602): #3374. See above.
|
||||
Map<String, dynamic> addTarget(dynamic e, Map<String, dynamic> serializedEvent) {
|
||||
Map<String, dynamic> addTarget(
|
||||
dynamic e, Map<String, dynamic> serializedEvent) {
|
||||
if (NODES_WITH_VALUE.contains(e.target.tagName.toLowerCase())) {
|
||||
serializedEvent['target'] = {'value': e.target.value};
|
||||
if (e.target is InputElement) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:code_transformers/messages/build_logger.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:guinness/guinness.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:source_span/source_span.dart';
|
||||
import '../common/read_file.dart';
|
||||
|
||||
var formatter = new DartFormatter();
|
||||
@@ -24,6 +25,14 @@ void allTests() {
|
||||
_testProcessor('should preserve parameter annotations as const instances.',
|
||||
'parameter_metadata/soup.dart');
|
||||
|
||||
_testProcessor('should handle `part` directives.', 'part_files/main.dart');
|
||||
|
||||
_testProcessor('should handle multiple `part` directives.',
|
||||
'multiple_part_files/main.dart');
|
||||
|
||||
_testProcessor('should not generate .ng_deps.dart for `part` files.',
|
||||
'part_files/part.dart');
|
||||
|
||||
_testProcessor('should recognize custom annotations with package: imports',
|
||||
'custom_metadata/package_soup.dart',
|
||||
customDescriptors: [
|
||||
@@ -166,8 +175,9 @@ void _testProcessor(String name, String inputPath,
|
||||
if (output == null) {
|
||||
expect(await reader.hasInput(expectedNgDepsId)).toBeFalse();
|
||||
} else {
|
||||
var input = await reader.readAsString(expectedNgDepsId);
|
||||
expect(formatter.format(output)).toEqual(formatter.format(input));
|
||||
var expectedOutput = await reader.readAsString(expectedNgDepsId);
|
||||
expect(formatter.format(output))
|
||||
.toEqual(formatter.format(expectedOutput));
|
||||
}
|
||||
if (ngMeta.isEmpty) {
|
||||
expect(await reader.hasInput(expectedAliasesId)).toBeFalse();
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
library main.ng_deps.dart;
|
||||
|
||||
import 'main.dart';
|
||||
export 'main.dart';
|
||||
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/annotations_impl/annotations.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
Part1Component,
|
||||
new _ngRef.ReflectionInfo(const [const Component(selector: '[part1]')],
|
||||
const [], () => new Part1Component()))
|
||||
..registerType(
|
||||
Part2Component,
|
||||
new _ngRef.ReflectionInfo(const [const Component(selector: '[part2]')],
|
||||
const [], () => new Part2Component()))
|
||||
..registerType(
|
||||
MainComponent,
|
||||
new _ngRef.ReflectionInfo(const [const Component(selector: '[main]')],
|
||||
const [], () => new MainComponent()));
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
library main;
|
||||
|
||||
import 'package:angular2/src/core/annotations_impl/annotations.dart';
|
||||
|
||||
part 'part1.dart';
|
||||
part 'part2.dart';
|
||||
|
||||
@Component(selector: '[main]')
|
||||
class MainComponent {
|
||||
MainComponent();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
part of main;
|
||||
|
||||
@Component(selector: '[part1]')
|
||||
class Part1Component {
|
||||
Part1Component();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
part of main;
|
||||
|
||||
@Component(selector: '[part2]')
|
||||
class Part2Component {
|
||||
Part2Component();
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
library main.ng_deps.dart;
|
||||
|
||||
import 'main.dart';
|
||||
export 'main.dart';
|
||||
import 'package:angular2/src/reflection/reflection.dart' as _ngRef;
|
||||
import 'package:angular2/src/core/annotations_impl/annotations.dart';
|
||||
|
||||
var _visited = false;
|
||||
void initReflector() {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
_ngRef.reflector
|
||||
..registerType(
|
||||
PartComponent,
|
||||
new _ngRef.ReflectionInfo(const [const Component(selector: '[part]')],
|
||||
const [], () => new PartComponent()))
|
||||
..registerType(
|
||||
MainComponent,
|
||||
new _ngRef.ReflectionInfo(const [const Component(selector: '[main]')],
|
||||
const [], () => new MainComponent()));
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
library main;
|
||||
|
||||
import 'package:angular2/src/core/annotations_impl/annotations.dart';
|
||||
|
||||
part 'part.dart';
|
||||
|
||||
@Component(selector: '[main]')
|
||||
class MainComponent {
|
||||
MainComponent();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
part of main;
|
||||
|
||||
@Component(selector: '[part]')
|
||||
class PartComponent {
|
||||
PartComponent();
|
||||
}
|
||||
Reference in New Issue
Block a user