Skip to content

Commit

Permalink
refactor(ngdart)!: migrate ViewEncapsulation to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ykmnkmi committed Mar 17, 2023
1 parent 3c5523a commit 2e15858
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions _tests/test/compiler/ast_directive_normalizer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ void main() {
type: CompileTypeMetadata(name: 'A', moduleUrl: 'package:a/a.dart'),
template: CompileTemplateMetadata(
template: '',
encapsulation: ViewEncapsulation.Emulated,
encapsulation: ViewEncapsulation.emulated,
),
);
metadata = await normalizer.normalizeDirective(metadata);
expect(metadata.template.encapsulation, ViewEncapsulation.None);
expect(metadata.template.encapsulation, ViewEncapsulation.none);
});

test('should resolve inline stylesheets', () async {
Expand Down Expand Up @@ -205,7 +205,7 @@ void main() {
),
);
metadata = await normalizer.normalizeDirective(metadata);
expect(metadata.template.encapsulation, ViewEncapsulation.Emulated);
expect(metadata.template.encapsulation, ViewEncapsulation.emulated);
expect(
metadata.template.styles,
[
Expand Down
4 changes: 2 additions & 2 deletions _tests/test/core/view/projection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class ManualViewportDirective {
selector: 'container-with-style-emu',
template: '<div class="blueStyle"></div>',
styles: ['.blueStyle { color: blue}'],
encapsulation: ViewEncapsulation.Emulated,
encapsulation: ViewEncapsulation.emulated,
directives: [SimpleComponent],
)
class ContainerWithStyleEmulated {}
Expand All @@ -290,7 +290,7 @@ class ContainerWithStyleEmulated {}
selector: 'container-with-style-not-emu',
template: '<div class="redStyle"></div>',
styles: ['.redStyle { color: red}'],
encapsulation: ViewEncapsulation.None,
encapsulation: ViewEncapsulation.none,
directives: [SimpleComponent],
)
class ContainerWithStyleNotEmulated {}
Expand Down
4 changes: 2 additions & 2 deletions ngcompiler/lib/v1/src/compiler/angular_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class AngularCompiler {
NormalizedComponentWithViewDirectives componentWithDirs,
) {
switch (componentWithDirs.component.template!.encapsulation) {
case ViewEncapsulation.Emulated:
case ViewEncapsulation.emulated:
return ir.ViewEncapsulation.emulated;
case ViewEncapsulation.None:
case ViewEncapsulation.none:
return ir.ViewEncapsulation.none;
default:
throw ArgumentError.value(
Expand Down
4 changes: 2 additions & 2 deletions ngcompiler/lib/v1/src/compiler/ast_directive_normalizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ class AstDirectiveNormalizer {

// Optimization: Turn off encapsulation when there are no styles to apply.
var encapsulation = templateMeta.encapsulation;
if (encapsulation == ViewEncapsulation.Emulated &&
if (encapsulation == ViewEncapsulation.emulated &&
templateMeta.styles.isEmpty &&
allExternalStyles.isEmpty) {
encapsulation = ViewEncapsulation.None;
encapsulation = ViewEncapsulation.none;
}

return CompileTemplateMetadata(
Expand Down
2 changes: 1 addition & 1 deletion ngcompiler/lib/v1/src/compiler/compile_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class CompileTemplateMetadata {
final List<String> styleUrls;
final List<String> ngContentSelectors;
CompileTemplateMetadata(
{this.encapsulation = ViewEncapsulation.Emulated,
{this.encapsulation = ViewEncapsulation.emulated,
this.template,
this.templateUrl,
this.templateOffset = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ class CompileView {
void shimCssForNode(NodeReference nodeReference, int nodeIndex,
CompileIdentifierMetadata nodeType) {
if (isRootNodeOfHost(nodeIndex)) return;
if (component.template!.encapsulation == ViewEncapsulation.Emulated) {
if (component.template!.encapsulation == ViewEncapsulation.emulated) {
// Set ng_content class for CSS shim.
var shimMethod =
nodeType != Identifiers.HTML_ELEMENT ? 'addShimC' : 'addShimE';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _ViewStyleLinker {
const _ViewStyleLinker(this._view, this._class);

bool get _hasScopedStyles =>
_view.component.template!.encapsulation == ViewEncapsulation.Emulated;
_view.component.template!.encapsulation == ViewEncapsulation.emulated;

o.ExternalExpr get _styleType => o.importExpr(_hasScopedStyles
? StyleEncapsulation.componentStylesScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ class _ComponentVisitor
value,
'encapsulation',
ViewEncapsulation.values,
defaultTo: ViewEncapsulation.Emulated,
defaultTo: ViewEncapsulation.emulated,
);

ChangeDetectionStrategy _changeDetection(
Expand Down
2 changes: 1 addition & 1 deletion ngdart/lib/src/meta/directives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class Component extends Directive {
this.directives = const [],
this.directiveTypes = const [],
this.pipes = const [],
this.encapsulation = ViewEncapsulation.Emulated,
this.encapsulation = ViewEncapsulation.emulated,
});
}

Expand Down
4 changes: 2 additions & 2 deletions ngdart/lib/src/meta/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ enum ViewEncapsulation {
/// adding the new Host Element attribute to all selectors.
///
/// This is the default option.
Emulated,
emulated,

/// Don't provide any template or style encapsulation.
None
none
}

0 comments on commit 2e15858

Please sign in to comment.