From dbf8b026564f768fd6a5fcd4368799a020c56960 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 29 Feb 2016 11:13:20 -0800 Subject: [PATCH] Use single-quoted strings in certain places. --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 2 +- src/compiler/declarationEmitter.ts | 6 ++--- src/compiler/emitter.ts | 40 +++++++++++++++--------------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 26f16c730fb..1f19d01b9cb 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1221,7 +1221,7 @@ namespace ts { // Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the // string to contain unicode escapes (as per ES5). - return nodeText === "\"use strict\"" || nodeText === "'use strict'"; + return nodeText === '"use strict"' || nodeText === "'use strict'"; } function bindWorker(node: Node) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2a14e5b9a0..4926ee6fa08 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1159,7 +1159,7 @@ namespace ts { const isRelative = isExternalModuleNameRelative(moduleName); if (!isRelative) { - const symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule); + const symbol = getSymbol(globals, '"' + moduleName + '"', SymbolFlags.ValueModule); if (symbol) { // merged symbol is module declaration symbol combined with all augmentations return getMergedSymbol(symbol); diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 0c7fa5e8dda..0b5ffca4b53 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -753,9 +753,9 @@ namespace ts { if (moduleSpecifier.kind === SyntaxKind.StringLiteral && isBundledEmit && (compilerOptions.out || compilerOptions.outFile)) { const moduleName = getExternalModuleNameFromDeclaration(host, resolver, parent); if (moduleName) { - write("\""); + write('"'); write(moduleName); - write("\""); + write('"'); return; } } @@ -1679,7 +1679,7 @@ namespace ts { host.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); - referencePathsOutput += "/// " + newLine; + referencePathsOutput += '/// ' + newLine; } return addedBundledEmitReference; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c826cd77441..a91d7a68b8c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -966,7 +966,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // Any template literal or string literal with an extended escape // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. if (languageVersion < ScriptTarget.ES6 && (isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { - return getQuotedEscapedLiteralText("\"", node.text, "\""); + return getQuotedEscapedLiteralText('"', node.text, '"'); } // If we don't need to downlevel and we can reach the original source text using @@ -979,7 +979,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // or an escaped quoted form of the original text if it's string-like. switch (node.kind) { case SyntaxKind.StringLiteral: - return getQuotedEscapedLiteralText("\"", node.text, "\""); + return getQuotedEscapedLiteralText('"', node.text, '"'); case SyntaxKind.NoSubstitutionTemplateLiteral: return getQuotedEscapedLiteralText("`", node.text, "`"); case SyntaxKind.TemplateHead: @@ -1205,9 +1205,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge /// 'Div' for upper-cased or dotted names function emitTagName(name: Identifier | QualifiedName) { if (name.kind === SyntaxKind.Identifier && isIntrinsicJsxName((name).text)) { - write("\""); + write('"'); emit(name); - write("\""); + write('"'); } else { emit(name); @@ -1222,9 +1222,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emit(name); } else { - write("\""); + write('"'); emit(name); - write("\""); + write('"'); } } @@ -1493,7 +1493,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge emit((node).expression); } else { - write("\""); + write('"'); if (node.kind === SyntaxKind.NumericLiteral) { write((node).text); @@ -1502,7 +1502,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge writeTextOfNode(currentText, node); } - write("\""); + write('"'); } } @@ -1592,7 +1592,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (declaration.kind === SyntaxKind.ImportClause) { // Identifier references default import write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default"); + write(languageVersion === ScriptTarget.ES3 ? '["default"]' : ".default"); return; } else if (declaration.kind === SyntaxKind.ImportSpecifier) { @@ -1601,7 +1601,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge const name = (declaration).propertyName || (declaration).name; const identifier = getTextOfNodeFromSourceText(currentText, name); if (languageVersion === ScriptTarget.ES3 && identifier === "default") { - write(`["default"]`); + write('["default"]'); } else { write("."); @@ -3792,7 +3792,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (!isEs6Module) { if (languageVersion !== ScriptTarget.ES3) { // default value of configurable, enumerable, writable are `false`. - write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + write('Object.defineProperty(exports, "__esModule", { value: true });'); writeLine(); } else { @@ -3828,7 +3828,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge if (node.flags & NodeFlags.Default) { emitEs6ExportDefaultCompat(node); if (languageVersion === ScriptTarget.ES3) { - write("exports[\"default\"]"); + write('exports["default"]'); } else { write("exports.default"); @@ -6600,7 +6600,7 @@ const _super = (function (geti, seti) { emitEs6ExportDefaultCompat(node); emitContainingModuleName(node); if (languageVersion === ScriptTarget.ES3) { - write("[\"default\"] = "); + write('["default"] = '); } else { write(".default = "); @@ -7322,11 +7322,11 @@ const _super = (function (geti, seti) { // Fill in amd-dependency tags for (const amdDependency of node.amdDependencies) { if (amdDependency.name) { - aliasedModuleNames.push("\"" + amdDependency.path + "\""); + aliasedModuleNames.push('"' + amdDependency.path + '"'); importAliasNames.push(amdDependency.name); } else { - unaliasedModuleNames.push("\"" + amdDependency.path + "\""); + unaliasedModuleNames.push('"' + amdDependency.path + '"'); } } @@ -7368,7 +7368,7 @@ const _super = (function (geti, seti) { } function emitAMDDependencyList({ aliasedModuleNames, unaliasedModuleNames }: AMDDependencyNames) { - write("[\"require\", \"exports\""); + write('["require", "exports"'); if (aliasedModuleNames.length) { write(", "); write(aliasedModuleNames.join(", ")); @@ -7502,7 +7502,7 @@ const _super = (function (geti, seti) { if (isLineBreak(c)) { if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { const part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + escapeString(part); + result = (result ? result + `" + ' ' + "` : "") + escapeString(part); } firstNonWhitespace = -1; } @@ -7525,7 +7525,7 @@ const _super = (function (geti, seti) { if (entities[m] !== undefined) { const ch = String.fromCharCode(entities[m]); // " needs to be escaped - return ch === "\"" ? "\\\"" : ch; + return ch === '"' ? "\\\"" : ch; } else { return s; @@ -7569,9 +7569,9 @@ const _super = (function (geti, seti) { function emitJsxText(node: JsxText) { switch (compilerOptions.jsx) { case JsxEmit.React: - write("\""); + write('"'); write(trimReactWhitespaceAndApplyEntities(node)); - write("\""); + write('"'); break; case JsxEmit.Preserve: