make ts compiler options more strict
This commit is contained in:
parent
7bf0c138b8
commit
8c8fe8d131
@ -9,12 +9,12 @@ const MARKER_IMPORT_NAME = 'marker';
|
|||||||
|
|
||||||
export class MarkerParser implements ParserInterface {
|
export class MarkerParser implements ParserInterface {
|
||||||
|
|
||||||
public extract(contents: string, filePath: string): TranslationCollection | null {
|
public extract(source: string, filePath: string): TranslationCollection | null {
|
||||||
const sourceFile = tsquery.ast(contents, filePath);
|
const sourceFile = tsquery.ast(source, filePath);
|
||||||
|
|
||||||
const markerImportName = getNamedImportAlias(sourceFile, MARKER_MODULE_NAME, MARKER_IMPORT_NAME);
|
const markerImportName = getNamedImportAlias(sourceFile, MARKER_MODULE_NAME, MARKER_IMPORT_NAME);
|
||||||
if (!markerImportName) {
|
if (!markerImportName) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let collection: TranslationCollection = new TranslationCollection();
|
let collection: TranslationCollection = new TranslationCollection();
|
||||||
|
@ -14,7 +14,7 @@ export class ServiceParser implements ParserInterface {
|
|||||||
|
|
||||||
const classDeclarations = findClassDeclarations(sourceFile);
|
const classDeclarations = findClassDeclarations(sourceFile);
|
||||||
if (!classDeclarations) {
|
if (!classDeclarations) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let collection: TranslationCollection = new TranslationCollection();
|
let collection: TranslationCollection = new TranslationCollection();
|
||||||
|
@ -22,7 +22,7 @@ export function getNamedImports(node: Node, moduleName: string): NamedImports[]
|
|||||||
export function getNamedImportAlias(node: Node, moduleName: string, importName: string): string | null {
|
export function getNamedImportAlias(node: Node, moduleName: string, importName: string): string | null {
|
||||||
const [namedImportNode] = getNamedImports(node, moduleName);
|
const [namedImportNode] = getNamedImports(node, moduleName);
|
||||||
if (!namedImportNode) {
|
if (!namedImportNode) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = `ImportSpecifier:has(Identifier[name="${importName}"]) > Identifier`;
|
const query = `ImportSpecifier:has(Identifier[name="${importName}"]) > Identifier`;
|
||||||
@ -88,7 +88,7 @@ export function getStringsFromExpression(expression: Expression): string[] {
|
|||||||
|
|
||||||
if (isArrayLiteralExpression(expression)) {
|
if (isArrayLiteralExpression(expression)) {
|
||||||
return expression.elements.reduce((result: string[], element: Expression) => {
|
return expression.elements.reduce((result: string[], element: Expression) => {
|
||||||
const strings = this.getStringsFromExpression(element);
|
const strings = getStringsFromExpression(element);
|
||||||
return [
|
return [
|
||||||
...result,
|
...result,
|
||||||
...strings
|
...strings
|
||||||
@ -97,8 +97,8 @@ export function getStringsFromExpression(expression: Expression): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isBinaryExpression(expression)) {
|
if (isBinaryExpression(expression)) {
|
||||||
const [left] = this.getStringsFromExpression(expression.left);
|
const [left] = getStringsFromExpression(expression.left);
|
||||||
const [right] = this.getStringsFromExpression(expression.right);
|
const [right] = getStringsFromExpression(expression.right);
|
||||||
|
|
||||||
if (expression.operatorToken.kind === SyntaxKind.PlusToken) {
|
if (expression.operatorToken.kind === SyntaxKind.PlusToken) {
|
||||||
if (typeof left === 'string' && typeof right === 'string') {
|
if (typeof left === 'string' && typeof right === 'string') {
|
||||||
@ -119,8 +119,8 @@ export function getStringsFromExpression(expression: Expression): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isConditionalExpression(expression)) {
|
if (isConditionalExpression(expression)) {
|
||||||
const [whenTrue] = this.getStringsFromExpression(expression.whenTrue);
|
const [whenTrue] = getStringsFromExpression(expression.whenTrue);
|
||||||
const [whenFalse] = this.getStringsFromExpression(expression.whenFalse);
|
const [whenFalse] = getStringsFromExpression(expression.whenFalse);
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
if (typeof whenTrue === 'string') {
|
if (typeof whenTrue === 'string') {
|
||||||
|
@ -33,7 +33,7 @@ export class TranslationCollection {
|
|||||||
|
|
||||||
public filter(callback: (key?: string, val?: string) => boolean): TranslationCollection {
|
public filter(callback: (key?: string, val?: string) => boolean): TranslationCollection {
|
||||||
let values: TranslationType = {};
|
let values: TranslationType = {};
|
||||||
this.forEach((key: string, val: string) => {
|
this.forEach((key, val) => {
|
||||||
if (callback.call(this, key, val)) {
|
if (callback.call(this, key, val)) {
|
||||||
values[key] = val;
|
values[key] = val;
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ export class TranslationCollection {
|
|||||||
|
|
||||||
public map(callback: (key?: string, val?: string) => string): TranslationCollection {
|
public map(callback: (key?: string, val?: string) => string): TranslationCollection {
|
||||||
let values: TranslationType = {};
|
let values: TranslationType = {};
|
||||||
this.forEach((key: string, val: string) => {
|
this.forEach((key, val) => {
|
||||||
values[key] = callback.call(this, key, val);
|
values[key] = callback.call(this, key, val);
|
||||||
});
|
});
|
||||||
return new TranslationCollection(values);
|
return new TranslationCollection(values);
|
||||||
@ -56,7 +56,7 @@ export class TranslationCollection {
|
|||||||
public intersect(collection: TranslationCollection): TranslationCollection {
|
public intersect(collection: TranslationCollection): TranslationCollection {
|
||||||
let values: TranslationType = {};
|
let values: TranslationType = {};
|
||||||
this.filter(key => collection.has(key))
|
this.filter(key => collection.has(key))
|
||||||
.forEach((key: string, val: string) => {
|
this.forEach((key, val) => {
|
||||||
values[key] = val;
|
values[key] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noImplicitThis": true,
|
||||||
|
"noImplicitUseStrict": true,
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"target": "es2015",
|
"target": "es2015",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user