mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 03:01:51 +08:00
feat: allow better tree shaking (#9798)
This commit is contained in:
@ -3,7 +3,7 @@ import { isCssVariable } from '../../core/properties';
|
||||
import { isNullOrUndefined } from '../../../utils/types';
|
||||
|
||||
import * as cssParser from '../../../css';
|
||||
import * as parser from '../../../css/parser';
|
||||
import { Combinator as ICombinator , SimpleSelectorSequence as ISimpleSelectorSequence, Selector as ISelector, SimpleSelector as ISimpleSelector, parseSelector} from '../../../css/parser';
|
||||
|
||||
/**
|
||||
* An interface describing the shape of a type on which the selectors may apply.
|
||||
@ -527,7 +527,7 @@ function createDeclaration(decl: cssParser.Declaration): any {
|
||||
return { property: isCssVariable(decl.property) ? decl.property : decl.property.toLowerCase(), value: decl.value };
|
||||
}
|
||||
|
||||
function createSimpleSelectorFromAst(ast: parser.SimpleSelector): SimpleSelector {
|
||||
function createSimpleSelectorFromAst(ast: ISimpleSelector): SimpleSelector {
|
||||
if (ast.type === '.') {
|
||||
return new ClassSelector(ast.identifier);
|
||||
}
|
||||
@ -553,7 +553,7 @@ function createSimpleSelectorFromAst(ast: parser.SimpleSelector): SimpleSelector
|
||||
}
|
||||
}
|
||||
|
||||
function createSimpleSelectorSequenceFromAst(ast: parser.SimpleSelectorSequence): SimpleSelectorSequence | SimpleSelector {
|
||||
function createSimpleSelectorSequenceFromAst(ast: ISimpleSelectorSequence): SimpleSelectorSequence | SimpleSelector {
|
||||
if (ast.length === 0) {
|
||||
return new InvalidSelector(new Error('Empty simple selector sequence.'));
|
||||
} else if (ast.length === 1) {
|
||||
@ -563,7 +563,7 @@ function createSimpleSelectorSequenceFromAst(ast: parser.SimpleSelectorSequence)
|
||||
}
|
||||
}
|
||||
|
||||
function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSelectorSequence | Selector {
|
||||
function createSelectorFromAst(ast: ISelector): SimpleSelector | SimpleSelectorSequence | Selector {
|
||||
if (ast.length === 0) {
|
||||
return new InvalidSelector(new Error('Empty selector.'));
|
||||
} else if (ast.length === 1) {
|
||||
@ -571,10 +571,10 @@ function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSel
|
||||
} else {
|
||||
const simpleSelectorSequences = [];
|
||||
let simpleSelectorSequence: SimpleSelectorSequence | SimpleSelector;
|
||||
let combinator: parser.Combinator;
|
||||
let combinator: ICombinator;
|
||||
for (let i = 0; i < ast.length; i++) {
|
||||
simpleSelectorSequence = createSimpleSelectorSequenceFromAst(<parser.SimpleSelectorSequence>ast[i][0]);
|
||||
combinator = <parser.Combinator>ast[i][1];
|
||||
simpleSelectorSequence = createSimpleSelectorSequenceFromAst(<ISimpleSelectorSequence>ast[i][0]);
|
||||
combinator = <ICombinator>ast[i][1];
|
||||
if (combinator) {
|
||||
simpleSelectorSequence.combinator = combinator;
|
||||
}
|
||||
@ -587,7 +587,7 @@ function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSel
|
||||
|
||||
export function createSelector(sel: string): SimpleSelector | SimpleSelectorSequence | Selector {
|
||||
try {
|
||||
const parsedSelector = parser.parseSelector(sel);
|
||||
const parsedSelector = parseSelector(sel);
|
||||
if (!parsedSelector) {
|
||||
return new InvalidSelector(new Error('Empty selector'));
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CoreTypes } from '../../core-types';
|
||||
import { Color } from '../../color';
|
||||
import { ColorStop } from './gradient';
|
||||
import { LinearGradient as CSSLinearGradient } from '../../css/parser';
|
||||
import type { LinearGradient as CSSLinearGradient } from '../../css/parser';
|
||||
|
||||
export class LinearGradient {
|
||||
public angle: number;
|
||||
|
@ -14,7 +14,7 @@ import { decompose2DTransformMatrix, getTransformMatrix, matrixArrayToCssMatrix,
|
||||
import { Trace } from '../../trace';
|
||||
import { CoreTypes } from '../../core-types';
|
||||
|
||||
import * as parser from '../../css/parser';
|
||||
import { parseBackground } from '../../css/parser';
|
||||
import { LinearGradient } from './linear-gradient';
|
||||
import { CSSShadow, parseCSSShadow } from './css-shadow';
|
||||
|
||||
@ -785,7 +785,7 @@ export const backgroundImageProperty = new CssProperty<Style, string | LinearGra
|
||||
},
|
||||
valueConverter: (value: any) => {
|
||||
if (typeof value === 'string') {
|
||||
const parsed = parser.parseBackground(value);
|
||||
const parsed = parseBackground(value);
|
||||
if (parsed) {
|
||||
value = typeof parsed.value.image === 'object' ? LinearGradient.parse(parsed.value.image) : value;
|
||||
}
|
||||
@ -837,7 +837,7 @@ backgroundPositionProperty.register(Style);
|
||||
|
||||
function convertToBackgrounds(this: void, value: string): [CssProperty<any, any>, any][] {
|
||||
if (typeof value === 'string') {
|
||||
const backgrounds = parser.parseBackground(value).value;
|
||||
const backgrounds = parseBackground(value).value;
|
||||
let backgroundColor = unsetValue;
|
||||
if (backgrounds.color) {
|
||||
backgroundColor = backgrounds.color instanceof Color ? backgrounds.color : new Color(backgrounds.color);
|
||||
|
Reference in New Issue
Block a user