mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
fix up lint errors, cleanup build folder
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"no-undef": 2,
|
||||
"no-unused-vars": 1
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*global require,exports,__dirname,Buffer,setTimeout*/
|
||||
|
||||
var path = require('path');
|
||||
var gulp = require('gulp');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
|
||||
@@ -3,13 +3,9 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*global require,__dirname*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
var path = require('path');
|
||||
var filter = require('gulp-filter');
|
||||
var _ = require('underscore');
|
||||
var es = require('event-stream');
|
||||
var buildfile = require('../src/buildfile');
|
||||
var util = require('./lib/util');
|
||||
var common = require('./gulpfile.common');
|
||||
@@ -80,19 +76,4 @@ gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common
|
||||
|
||||
gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
|
||||
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor', true));
|
||||
|
||||
// Package
|
||||
|
||||
var root = path.dirname(__dirname);
|
||||
|
||||
function copyTask(src, dest, FILTER) {
|
||||
return function () {
|
||||
return (
|
||||
gulp.src(src + '/**', { base: src })
|
||||
.pipe(FILTER ? filter(FILTER) : es.through())
|
||||
.pipe(gulp.dest(dest))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
gulp.task('editor-distro', ['minify-editor', 'optimize-editor']);
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*global process,require,__dirname*/
|
||||
|
||||
// Increase max listeners for event emitters
|
||||
require('events').EventEmitter.defaultMaxListeners = 100;
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*global process,__dirname,Buffer,require*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
"use strict";
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var vm = require('vm');
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ export function bundle(entryPoints:IEntryPoint[], config:ILoaderConfig, callback
|
||||
loader(Object.keys(entryPointsMap), () => {
|
||||
let modules = <IBuildModuleInfo[]>loader.getBuildInfo();
|
||||
callback(null, emitEntryPoints(modules, entryPointsMap));
|
||||
}, (err) => callback(err, null))
|
||||
}, (err) => callback(err, null));
|
||||
}
|
||||
|
||||
function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap): IConcatFile[] {
|
||||
@@ -181,7 +181,7 @@ function emitEntryPoint(modulesMap:IBuildModuleInfoMap, deps:IGraph, entryPoint:
|
||||
usedPlugins[pluginName] = modulesMap[pluginName].exports;
|
||||
}
|
||||
return usedPlugins[pluginName];
|
||||
}
|
||||
};
|
||||
|
||||
includedModules.forEach((c:string) => {
|
||||
let bangIndex = c.indexOf('!');
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
|
||||
+5
-24
@@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var ts = require('./typescript/typescriptServices');
|
||||
var lazy = require('lazy.js');
|
||||
var event_stream_1 = require('event-stream');
|
||||
@@ -27,26 +28,6 @@ function collect(node, fn) {
|
||||
loop(node);
|
||||
return result;
|
||||
}
|
||||
function zip(stream, zipper) {
|
||||
if (zipper === void 0) { zipper = function (a, b) { return [a, b]; }; }
|
||||
var pass = event_stream_1.through();
|
||||
var oneBuffer = [];
|
||||
var otherBuffer = [];
|
||||
var result = pass.pipe(event_stream_1.through(function (f) {
|
||||
oneBuffer.push(f);
|
||||
flush();
|
||||
}), function () {
|
||||
flush();
|
||||
result.emit('end');
|
||||
});
|
||||
function flush() {
|
||||
while (oneBuffer.length > 0 && otherBuffer.length > 0) {
|
||||
result.emit('data', zipper(oneBuffer.shift(), otherBuffer.shift()));
|
||||
}
|
||||
}
|
||||
stream.pipe(event_stream_1.through(function (f) { return otherBuffer.push(f); }));
|
||||
return event_stream_1.duplex(pass, result);
|
||||
}
|
||||
function template(lines) {
|
||||
var indent = '', wrap = '';
|
||||
if (lines.length > 1) {
|
||||
@@ -119,7 +100,7 @@ var nls;
|
||||
this.lib = ts.ScriptSnapshot.fromString('');
|
||||
}
|
||||
return SingleFileServiceHost;
|
||||
})();
|
||||
}());
|
||||
nls_1.SingleFileServiceHost = SingleFileServiceHost;
|
||||
function isCallExpressionWithinTextSpanCollectStep(textSpan, node) {
|
||||
if (!ts.textSpanContainsTextSpan({ start: node.pos, length: node.end - node.pos }, textSpan)) {
|
||||
@@ -140,13 +121,13 @@ var nls;
|
||||
.filter(function (n) { return n.kind === 211 /* ImportEqualsDeclaration */; })
|
||||
.map(function (n) { return n; })
|
||||
.filter(function (d) { return d.moduleReference.kind === 222 /* ExternalModuleReference */; })
|
||||
.filter(function (d) { return d.moduleReference.expression.getText() === "'vs/nls'"; });
|
||||
.filter(function (d) { return d.moduleReference.expression.getText() === '\'vs/nls\''; });
|
||||
// import ... from 'vs/nls';
|
||||
var importDeclarations = imports
|
||||
.filter(function (n) { return n.kind === 212 /* ImportDeclaration */; })
|
||||
.map(function (n) { return n; })
|
||||
.filter(function (d) { return d.moduleSpecifier.kind === 8 /* StringLiteral */; })
|
||||
.filter(function (d) { return d.moduleSpecifier.getText() === "'vs/nls'"; })
|
||||
.filter(function (d) { return d.moduleSpecifier.getText() === '\'vs/nls\''; })
|
||||
.filter(function (d) { return !!d.importClause && !!d.importClause.namedBindings; });
|
||||
var nlsExpressions = importEqualsDeclarations
|
||||
.map(function (d) { return d.moduleReference.expression; })
|
||||
@@ -264,7 +245,7 @@ var nls;
|
||||
.flatten().toArray().join('');
|
||||
};
|
||||
return TextModel;
|
||||
})();
|
||||
}());
|
||||
nls_1.TextModel = TextModel;
|
||||
function patchJavascript(patches, contents, moduleId) {
|
||||
var model = new nls.TextModel(contents);
|
||||
|
||||
+4
-31
@@ -1,15 +1,12 @@
|
||||
import * as ts from './typescript/typescriptServices';
|
||||
import * as lazy from 'lazy.js';
|
||||
import { duplex, through, mapSync, readArray, merge } from 'event-stream';
|
||||
import { duplex, through } from 'event-stream';
|
||||
import { Stream } from 'stream';
|
||||
import { ThroughStream } from 'through';
|
||||
import File = require('vinyl');
|
||||
import * as sm from 'source-map';
|
||||
import assign = require('object-assign');
|
||||
import clone = require('clone');
|
||||
import filter = require('gulp-filter');
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
|
||||
declare class FileSourceMap extends File {
|
||||
public sourceMap: sm.RawSourceMap;
|
||||
@@ -41,30 +38,6 @@ function collect(node: ts.Node, fn: (node: ts.Node) => CollectStepResult): ts.No
|
||||
return result;
|
||||
}
|
||||
|
||||
function zip<A,B,R>(stream: Stream, zipper: (a: A, b: B) => R = (a,b) => <any> [a, b]): ThroughStream {
|
||||
const pass = through();
|
||||
const oneBuffer: any[] = [];
|
||||
const otherBuffer: any[] = [];
|
||||
|
||||
const result = pass.pipe(through(f => {
|
||||
oneBuffer.push(f);
|
||||
flush();
|
||||
}), () => {
|
||||
flush();
|
||||
result.emit('end');
|
||||
});
|
||||
|
||||
function flush() {
|
||||
while (oneBuffer.length > 0 && otherBuffer.length > 0) {
|
||||
result.emit('data', zipper(oneBuffer.shift(), otherBuffer.shift()));
|
||||
}
|
||||
}
|
||||
|
||||
stream.pipe(through(f => otherBuffer.push(f)));
|
||||
|
||||
return duplex(pass, result);
|
||||
}
|
||||
|
||||
function template(lines: string[]): string {
|
||||
let indent = '', wrap = '';
|
||||
|
||||
@@ -202,14 +175,14 @@ module nls {
|
||||
.filter(n => n.kind === ts.SyntaxKind.ImportEqualsDeclaration)
|
||||
.map(n => <ts.ImportEqualsDeclaration> n)
|
||||
.filter(d => d.moduleReference.kind === ts.SyntaxKind.ExternalModuleReference)
|
||||
.filter(d => (<ts.ExternalModuleReference>d.moduleReference).expression.getText() === "'vs/nls'");
|
||||
.filter(d => (<ts.ExternalModuleReference>d.moduleReference).expression.getText() === '\'vs/nls\'');
|
||||
|
||||
// import ... from 'vs/nls';
|
||||
const importDeclarations = imports
|
||||
.filter(n => n.kind === ts.SyntaxKind.ImportDeclaration)
|
||||
.map(n => <ts.ImportDeclaration> n)
|
||||
.filter(d => d.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
|
||||
.filter(d => d.moduleSpecifier.getText() === "'vs/nls'")
|
||||
.filter(d => d.moduleSpecifier.getText() === '\'vs/nls\'')
|
||||
.filter(d => !!d.importClause && !!d.importClause.namedBindings);
|
||||
|
||||
const nlsExpressions = importEqualsDeclarations
|
||||
@@ -244,7 +217,7 @@ module nls {
|
||||
const allLocalizeImportDeclarations = importDeclarations
|
||||
.filter(d => d.importClause.namedBindings.kind === ts.SyntaxKind.NamedImports)
|
||||
.map(d => (<ts.NamedImports> d.importClause.namedBindings).elements)
|
||||
.flatten()
|
||||
.flatten();
|
||||
|
||||
// `localize` read-only references
|
||||
const localizeReferences = allLocalizeImportDeclarations
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var es = require('event-stream');
|
||||
var _ = require('underscore');
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*global require,exports,process,Buffer*/
|
||||
|
||||
var es = require('event-stream');
|
||||
var debounce = require('debounce');
|
||||
var filter = require('gulp-filter');
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
"noImplicitAny": false,
|
||||
"removeComments": false,
|
||||
"preserveConstEnums": true,
|
||||
"target": "ES5",
|
||||
"target": "es5",
|
||||
"sourceMap": false,
|
||||
"experimentalDecorators": true,
|
||||
"noLib": true
|
||||
"noLib": true,
|
||||
"newLine": "LF"
|
||||
}
|
||||
}
|
||||
@@ -3,166 +3,166 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || function(d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var ts = require('typescript');
|
||||
var Lint = require('tslint/lib/lint');
|
||||
/**
|
||||
* Implementation of the no-unexternalized-strings rule.
|
||||
*/
|
||||
var Rule = (function(_super) {
|
||||
__extends(Rule, _super);
|
||||
function Rule() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
Rule.prototype.apply = function(sourceFile) {
|
||||
return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions()));
|
||||
};
|
||||
return Rule;
|
||||
} (Lint.Rules.AbstractRule));
|
||||
var Rule = (function (_super) {
|
||||
__extends(Rule, _super);
|
||||
function Rule() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
Rule.prototype.apply = function (sourceFile) {
|
||||
return this.applyWithWalker(new NoUnexternalizedStringsRuleWalker(sourceFile, this.getOptions()));
|
||||
};
|
||||
return Rule;
|
||||
}(Lint.Rules.AbstractRule));
|
||||
exports.Rule = Rule;
|
||||
function isStringLiteral(node) {
|
||||
return node && node.kind === ts.SyntaxKind.StringLiteral;
|
||||
return node && node.kind === ts.SyntaxKind.StringLiteral;
|
||||
}
|
||||
function isObjectLiteral(node) {
|
||||
return node && node.kind === ts.SyntaxKind.ObjectLiteralExpression;
|
||||
return node && node.kind === ts.SyntaxKind.ObjectLiteralExpression;
|
||||
}
|
||||
function isPropertyAssignment(node) {
|
||||
return node && node.kind === ts.SyntaxKind.PropertyAssignment;
|
||||
return node && node.kind === ts.SyntaxKind.PropertyAssignment;
|
||||
}
|
||||
var NoUnexternalizedStringsRuleWalker = (function(_super) {
|
||||
__extends(NoUnexternalizedStringsRuleWalker, _super);
|
||||
function NoUnexternalizedStringsRuleWalker(file, opts) {
|
||||
var _this = this;
|
||||
_super.call(this, file, opts);
|
||||
this.signatures = Object.create(null);
|
||||
this.ignores = Object.create(null);
|
||||
this.messageIndex = undefined;
|
||||
this.keyIndex = undefined;
|
||||
this.usedKeys = Object.create(null);
|
||||
var options = this.getOptions();
|
||||
var first = options && options.length > 0 ? options[0] : null;
|
||||
if (first) {
|
||||
if (Array.isArray(first.signatures)) {
|
||||
first.signatures.forEach(function(signature) { return _this.signatures[signature] = true; });
|
||||
}
|
||||
if (Array.isArray(first.ignores)) {
|
||||
first.ignores.forEach(function(ignore) { return _this.ignores[ignore] = true; });
|
||||
}
|
||||
if (typeof first.messageIndex !== 'undefined') {
|
||||
this.messageIndex = first.messageIndex;
|
||||
}
|
||||
if (typeof first.keyIndex !== 'undefined') {
|
||||
this.keyIndex = first.keyIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
NoUnexternalizedStringsRuleWalker.prototype.visitSourceFile = function(node) {
|
||||
var _this = this;
|
||||
_super.prototype.visitSourceFile.call(this, node);
|
||||
Object.keys(this.usedKeys).forEach(function(key) {
|
||||
var occurences = _this.usedKeys[key];
|
||||
if (occurences.length > 1) {
|
||||
occurences.forEach(function(occurence) {
|
||||
_this.addFailure((_this.createFailure(occurence.key.getStart(), occurence.key.getWidth(), "Duplicate key " + occurence.key.getText() + " with different message value.")));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.visitStringLiteral = function(node) {
|
||||
this.checkStringLiteral(node);
|
||||
_super.prototype.visitStringLiteral.call(this, node);
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.checkStringLiteral = function(node) {
|
||||
var text = node.getText();
|
||||
var doubleQuoted = text.length >= 2 && text[0] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE && text[text.length - 1] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE;
|
||||
var info = this.findDescribingParent(node);
|
||||
// Ignore strings in import and export nodes.
|
||||
if (info && info.ignoreUsage) {
|
||||
return;
|
||||
}
|
||||
var callInfo = info ? info.callInfo : null;
|
||||
var functionName = callInfo ? callInfo.callExpression.expression.getText() : null;
|
||||
if (functionName && this.ignores[functionName]) {
|
||||
return;
|
||||
}
|
||||
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
|
||||
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText()));
|
||||
return;
|
||||
}
|
||||
// We have a single quoted string outside a localize function name.
|
||||
if (!doubleQuoted && !this.signatures[functionName]) {
|
||||
return;
|
||||
}
|
||||
// We have a string that is a direct argument into the localize call.
|
||||
var keyArg = callInfo.argIndex === this.keyIndex
|
||||
? callInfo.callExpression.arguments[this.keyIndex]
|
||||
: null;
|
||||
if (keyArg) {
|
||||
if (isStringLiteral(keyArg)) {
|
||||
this.recordKey(keyArg, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);
|
||||
}
|
||||
else if (isObjectLiteral(keyArg)) {
|
||||
for (var i = 0; i < keyArg.properties.length; i++) {
|
||||
var property = keyArg.properties[i];
|
||||
if (isPropertyAssignment(property)) {
|
||||
var name_1 = property.name.getText();
|
||||
if (name_1 === 'key') {
|
||||
var initializer = property.initializer;
|
||||
if (isStringLiteral(initializer)) {
|
||||
this.recordKey(initializer, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var messageArg = callInfo.argIndex === this.messageIndex
|
||||
? callInfo.callExpression.arguments[this.messageIndex]
|
||||
: null;
|
||||
if (messageArg && messageArg !== node) {
|
||||
this.addFailure(this.createFailure(messageArg.getStart(), messageArg.getWidth(), "Message argument to '" + callInfo.callExpression.expression.getText() + "' must be a string literal."));
|
||||
return;
|
||||
}
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.recordKey = function(keyNode, messageNode) {
|
||||
var text = keyNode.getText();
|
||||
var occurences = this.usedKeys[text];
|
||||
if (!occurences) {
|
||||
occurences = [];
|
||||
this.usedKeys[text] = occurences;
|
||||
}
|
||||
if (messageNode) {
|
||||
if (occurences.some(function(pair) { return pair.message ? pair.message.getText() === messageNode.getText() : false; })) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
occurences.push({ key: keyNode, message: messageNode });
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.findDescribingParent = function(node) {
|
||||
var parent;
|
||||
while ((parent = node.parent)) {
|
||||
var kind = parent.kind;
|
||||
if (kind === ts.SyntaxKind.CallExpression) {
|
||||
var callExpression = parent;
|
||||
return { callInfo: { callExpression: callExpression, argIndex: callExpression.arguments.indexOf(node) } };
|
||||
}
|
||||
else if (kind === ts.SyntaxKind.ImportEqualsDeclaration || kind === ts.SyntaxKind.ImportDeclaration || kind === ts.SyntaxKind.ExportDeclaration) {
|
||||
return { ignoreUsage: true };
|
||||
}
|
||||
else if (kind === ts.SyntaxKind.VariableDeclaration || kind === ts.SyntaxKind.FunctionDeclaration || kind === ts.SyntaxKind.PropertyDeclaration
|
||||
|| kind === ts.SyntaxKind.MethodDeclaration || kind === ts.SyntaxKind.VariableDeclarationList || kind === ts.SyntaxKind.InterfaceDeclaration
|
||||
|| kind === ts.SyntaxKind.ClassDeclaration || kind === ts.SyntaxKind.EnumDeclaration || kind === ts.SyntaxKind.ModuleDeclaration
|
||||
|| kind === ts.SyntaxKind.TypeAliasDeclaration || kind === ts.SyntaxKind.SourceFile) {
|
||||
return null;
|
||||
}
|
||||
node = parent;
|
||||
}
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
|
||||
return NoUnexternalizedStringsRuleWalker;
|
||||
} (Lint.RuleWalker));
|
||||
var NoUnexternalizedStringsRuleWalker = (function (_super) {
|
||||
__extends(NoUnexternalizedStringsRuleWalker, _super);
|
||||
function NoUnexternalizedStringsRuleWalker(file, opts) {
|
||||
var _this = this;
|
||||
_super.call(this, file, opts);
|
||||
this.signatures = Object.create(null);
|
||||
this.ignores = Object.create(null);
|
||||
this.messageIndex = undefined;
|
||||
this.keyIndex = undefined;
|
||||
this.usedKeys = Object.create(null);
|
||||
var options = this.getOptions();
|
||||
var first = options && options.length > 0 ? options[0] : null;
|
||||
if (first) {
|
||||
if (Array.isArray(first.signatures)) {
|
||||
first.signatures.forEach(function (signature) { return _this.signatures[signature] = true; });
|
||||
}
|
||||
if (Array.isArray(first.ignores)) {
|
||||
first.ignores.forEach(function (ignore) { return _this.ignores[ignore] = true; });
|
||||
}
|
||||
if (typeof first.messageIndex !== 'undefined') {
|
||||
this.messageIndex = first.messageIndex;
|
||||
}
|
||||
if (typeof first.keyIndex !== 'undefined') {
|
||||
this.keyIndex = first.keyIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
NoUnexternalizedStringsRuleWalker.prototype.visitSourceFile = function (node) {
|
||||
var _this = this;
|
||||
_super.prototype.visitSourceFile.call(this, node);
|
||||
Object.keys(this.usedKeys).forEach(function (key) {
|
||||
var occurences = _this.usedKeys[key];
|
||||
if (occurences.length > 1) {
|
||||
occurences.forEach(function (occurence) {
|
||||
_this.addFailure((_this.createFailure(occurence.key.getStart(), occurence.key.getWidth(), "Duplicate key " + occurence.key.getText() + " with different message value.")));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.visitStringLiteral = function (node) {
|
||||
this.checkStringLiteral(node);
|
||||
_super.prototype.visitStringLiteral.call(this, node);
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.checkStringLiteral = function (node) {
|
||||
var text = node.getText();
|
||||
var doubleQuoted = text.length >= 2 && text[0] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE && text[text.length - 1] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE;
|
||||
var info = this.findDescribingParent(node);
|
||||
// Ignore strings in import and export nodes.
|
||||
if (info && info.ignoreUsage) {
|
||||
return;
|
||||
}
|
||||
var callInfo = info ? info.callInfo : null;
|
||||
var functionName = callInfo ? callInfo.callExpression.expression.getText() : null;
|
||||
if (functionName && this.ignores[functionName]) {
|
||||
return;
|
||||
}
|
||||
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
|
||||
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText()));
|
||||
return;
|
||||
}
|
||||
// We have a single quoted string outside a localize function name.
|
||||
if (!doubleQuoted && !this.signatures[functionName]) {
|
||||
return;
|
||||
}
|
||||
// We have a string that is a direct argument into the localize call.
|
||||
var keyArg = callInfo.argIndex === this.keyIndex
|
||||
? callInfo.callExpression.arguments[this.keyIndex]
|
||||
: null;
|
||||
if (keyArg) {
|
||||
if (isStringLiteral(keyArg)) {
|
||||
this.recordKey(keyArg, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);
|
||||
}
|
||||
else if (isObjectLiteral(keyArg)) {
|
||||
for (var i = 0; i < keyArg.properties.length; i++) {
|
||||
var property = keyArg.properties[i];
|
||||
if (isPropertyAssignment(property)) {
|
||||
var name_1 = property.name.getText();
|
||||
if (name_1 === 'key') {
|
||||
var initializer = property.initializer;
|
||||
if (isStringLiteral(initializer)) {
|
||||
this.recordKey(initializer, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var messageArg = callInfo.argIndex === this.messageIndex
|
||||
? callInfo.callExpression.arguments[this.messageIndex]
|
||||
: null;
|
||||
if (messageArg && messageArg !== node) {
|
||||
this.addFailure(this.createFailure(messageArg.getStart(), messageArg.getWidth(), "Message argument to '" + callInfo.callExpression.expression.getText() + "' must be a string literal."));
|
||||
return;
|
||||
}
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.recordKey = function (keyNode, messageNode) {
|
||||
var text = keyNode.getText();
|
||||
var occurences = this.usedKeys[text];
|
||||
if (!occurences) {
|
||||
occurences = [];
|
||||
this.usedKeys[text] = occurences;
|
||||
}
|
||||
if (messageNode) {
|
||||
if (occurences.some(function (pair) { return pair.message ? pair.message.getText() === messageNode.getText() : false; })) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
occurences.push({ key: keyNode, message: messageNode });
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.prototype.findDescribingParent = function (node) {
|
||||
var parent;
|
||||
while ((parent = node.parent)) {
|
||||
var kind = parent.kind;
|
||||
if (kind === ts.SyntaxKind.CallExpression) {
|
||||
var callExpression = parent;
|
||||
return { callInfo: { callExpression: callExpression, argIndex: callExpression.arguments.indexOf(node) } };
|
||||
}
|
||||
else if (kind === ts.SyntaxKind.ImportEqualsDeclaration || kind === ts.SyntaxKind.ImportDeclaration || kind === ts.SyntaxKind.ExportDeclaration) {
|
||||
return { ignoreUsage: true };
|
||||
}
|
||||
else if (kind === ts.SyntaxKind.VariableDeclaration || kind === ts.SyntaxKind.FunctionDeclaration || kind === ts.SyntaxKind.PropertyDeclaration
|
||||
|| kind === ts.SyntaxKind.MethodDeclaration || kind === ts.SyntaxKind.VariableDeclarationList || kind === ts.SyntaxKind.InterfaceDeclaration
|
||||
|| kind === ts.SyntaxKind.ClassDeclaration || kind === ts.SyntaxKind.EnumDeclaration || kind === ts.SyntaxKind.ModuleDeclaration
|
||||
|| kind === ts.SyntaxKind.TypeAliasDeclaration || kind === ts.SyntaxKind.SourceFile) {
|
||||
return null;
|
||||
}
|
||||
node = parent;
|
||||
}
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
|
||||
return NoUnexternalizedStringsRuleWalker;
|
||||
}(Lint.RuleWalker));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import * as Lint from 'tslint/lib/lint';
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"moduleResolution": "node",
|
||||
"newLine": "LF"
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ var nls = require('./build/lib/nls');
|
||||
var util = require('./build/lib/util');
|
||||
var reporter = require('./build/lib/reporter')();
|
||||
var remote = require('gulp-remote-src');
|
||||
var rename = require('gulp-rename');
|
||||
var zip = require('gulp-vinyl-zip');
|
||||
var path = require('path');
|
||||
var bom = require('gulp-bom');
|
||||
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ if (!!process.send && process.env.PIPE_LOGGING === 'true') {
|
||||
// error when we are inside a forked process and this process tries to access those channels.
|
||||
var stream = require('stream');
|
||||
var writable = new stream.Writable({
|
||||
write: function (chunk, encoding, next) { /* No OP */ }
|
||||
write: function () { /* No OP */ }
|
||||
});
|
||||
|
||||
process.__defineGetter__('stdout', function() { return writable; });
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
"noImplicitAny": false,
|
||||
"removeComments": false,
|
||||
"preserveConstEnums": true,
|
||||
"target": "ES5",
|
||||
"target": "es5",
|
||||
"sourceMap": false,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
|
||||
+2
-1
@@ -3,7 +3,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*global process,__dirname,define,run,suite,test*/
|
||||
/*eslint-env mocha*/
|
||||
/*global define,run*/
|
||||
|
||||
var assert = require('assert');
|
||||
var path = require('path');
|
||||
|
||||
+1
-1
@@ -42,6 +42,6 @@ app.get('/', function (req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
var server = app.listen(port, function () {
|
||||
app.listen(port, function () {
|
||||
console.log('http://localhost:8887/');
|
||||
});
|
||||
Reference in New Issue
Block a user