UNPKG

3.17 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3// See LICENSE in the project root for license information.
4var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5 if (k2 === undefined) k2 = k;
6 var desc = Object.getOwnPropertyDescriptor(m, k);
7 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8 desc = { enumerable: true, get: function() { return m[k]; } };
9 }
10 Object.defineProperty(o, k2, desc);
11}) : (function(o, m, k, k2) {
12 if (k2 === undefined) k2 = k;
13 o[k2] = m[k];
14}));
15var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16 Object.defineProperty(o, "default", { enumerable: true, value: v });
17}) : function(o, v) {
18 o["default"] = v;
19});
20var __importStar = (this && this.__importStar) || function (mod) {
21 if (mod && mod.__esModule) return mod;
22 var result = {};
23 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24 __setModuleDefault(result, mod);
25 return result;
26};
27Object.defineProperty(exports, "__esModule", { value: true });
28exports.SourceFileLocationFormatter = void 0;
29const path = __importStar(require("path"));
30const node_core_library_1 = require("@rushstack/node-core-library");
31class SourceFileLocationFormatter {
32 /**
33 * Returns a string such as this, based on the context information in the provided node:
34 * "[C:\Folder\File.ts#123]"
35 */
36 static formatDeclaration(node, workingPackageFolderPath) {
37 const sourceFile = node.getSourceFile();
38 const lineAndCharacter = sourceFile.getLineAndCharacterOfPosition(node.getStart());
39 return SourceFileLocationFormatter.formatPath(sourceFile.fileName, {
40 sourceFileLine: lineAndCharacter.line + 1,
41 sourceFileColumn: lineAndCharacter.character + 1,
42 workingPackageFolderPath
43 });
44 }
45 static formatPath(sourceFilePath, options) {
46 if (!options) {
47 options = {};
48 }
49 let result = '';
50 // Make the path relative to the workingPackageFolderPath
51 let scrubbedPath = sourceFilePath;
52 if (options.workingPackageFolderPath) {
53 // If it's under the working folder, make it a relative path
54 if (node_core_library_1.Path.isUnderOrEqual(sourceFilePath, options.workingPackageFolderPath)) {
55 scrubbedPath = path.relative(options.workingPackageFolderPath, sourceFilePath);
56 }
57 }
58 // Convert it to a Unix-style path
59 scrubbedPath = node_core_library_1.Text.replaceAll(scrubbedPath, '\\', '/');
60 result += scrubbedPath;
61 if (options.sourceFileLine) {
62 result += `:${options.sourceFileLine}`;
63 if (options.sourceFileColumn) {
64 result += `:${options.sourceFileColumn}`;
65 }
66 }
67 return result;
68 }
69}
70exports.SourceFileLocationFormatter = SourceFileLocationFormatter;
71//# sourceMappingURL=SourceFileLocationFormatter.js.map
\No newline at end of file