mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00

Add parsers for the background css shorthand property, make ViewBase unit testable in node environment Add background parser and linear-gradient parser Use sticky regexes Simplify some types, introduce generic Parsed<T> instead of & TokenRange Apply each parser to return a { start, end, value } object Move the css selector parser to the css/parser and unify types Add the first steps toward building homegrown css parser Add somewhat standards compliant tokenizer, add baseline, rework and shady css parsers Enable all tests again, skip flaky perf test Improve css parser tokenizer by converting some char token types to simple string Implement 'parse a stylesheet' Add gonzales css-parser Add parseLib and css-tree perf Add a thin parser layer that will convert CSS3 tokens to values, for now output is compatible with rework Make root tsc green Return the requires of tns-core-modules to use relative paths for webpack to work Implement support for '@import 'url-string'; Fix function parser, function-token is no-longer neglected Make the style-scope be able to load from "css" and "css-ast" modules Add a loadAppCss event so theme can be added to snapshot separately from loaded
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { knownFolders } from "../file-system"
|
|
import { isAndroid } from "../platform"
|
|
|
|
export var debug = true;
|
|
|
|
var applicationRootPath: string;
|
|
function ensureAppRootPath() {
|
|
if (!applicationRootPath) {
|
|
applicationRootPath = knownFolders.currentApp().path;
|
|
applicationRootPath = applicationRootPath.substr(0, applicationRootPath.length - "app/".length);
|
|
}
|
|
}
|
|
|
|
export class Source {
|
|
private _uri: string;
|
|
private _line: number;
|
|
private _column: number;
|
|
|
|
private static _source: symbol = Symbol("source");
|
|
|
|
constructor(uri: string, line: number, column: number) {
|
|
ensureAppRootPath();
|
|
|
|
if (uri.length > applicationRootPath.length && uri.substr(0, applicationRootPath.length) === applicationRootPath) {
|
|
this._uri = "file://" + uri.substr(applicationRootPath.length);
|
|
} else {
|
|
this._uri = uri;
|
|
}
|
|
this._line = line;
|
|
this._column = column;
|
|
}
|
|
|
|
get uri(): string { return this._uri; }
|
|
get line(): number { return this._line; }
|
|
get column(): number { return this._column; }
|
|
|
|
public toString() {
|
|
return this._uri + ":" + this._line + ":" + this._column;
|
|
}
|
|
|
|
public static get(object: any): Source {
|
|
return object[Source._source];
|
|
}
|
|
|
|
public static set(object: any, src: Source) {
|
|
object[Source._source] = src;
|
|
}
|
|
}
|
|
|
|
export class ScopeError extends Error {
|
|
constructor(inner: Error, message?: string) {
|
|
let formattedMessage;
|
|
if (message && inner.message) {
|
|
formattedMessage = message + "\n > " + inner.message.replace("\n", "\n ");
|
|
} else {
|
|
formattedMessage = message || inner.message || undefined;
|
|
}
|
|
super(formattedMessage);
|
|
this.stack = isAndroid ? "Error: " + this.message + "\n" + inner.stack.substr(inner.stack.indexOf("\n") + 1) : inner.stack;
|
|
this.message = formattedMessage;
|
|
}
|
|
}
|
|
|
|
export class SourceError extends ScopeError {
|
|
constructor(child: Error, source: Source, message?: string) {
|
|
super(child, message ? message + " @" + source + "" : source + "");
|
|
}
|
|
}
|