mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-11-06 05:09:20 +08:00
R=aerotwist@chromium.org Bug: 1187573 Change-Id: I12afe682c2781651ff7cdc1650843010e2c8cbfd Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2826294 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
// Copyright 2021 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/* eslint-disable rulesdir/no_underscored_properties */
|
|
|
|
import * as Platform from '../../core/platform/platform.js';
|
|
import * as TextUtils from '../../models/text_utils/text_utils.js';
|
|
|
|
import {javaScriptOutline} from './JavaScriptOutline.js';
|
|
export interface Item {
|
|
title: string;
|
|
subtitle?: string;
|
|
line: number;
|
|
column: number;
|
|
}
|
|
|
|
export function htmlOutline(content: string, chunkCallback: (arg0: {
|
|
chunk: Array<Item>,
|
|
isLastChunk: boolean,
|
|
}) => void): void {
|
|
const SCRIPT_OPENING_TAG = /<script[^>]*>/im;
|
|
const SCRIPT_CLOSING_TAG = /<\/script\s*>/im;
|
|
|
|
const textCursor = new TextUtils.TextCursor.TextCursor(Platform.StringUtilities.findLineEndingIndexes(content));
|
|
while (true) {
|
|
// Look for the opening <script> tag.
|
|
const openingMatch = SCRIPT_OPENING_TAG.exec(content.substring(textCursor.offset()));
|
|
if (!openingMatch) {
|
|
break;
|
|
}
|
|
const scriptStart = textCursor.offset() + openingMatch.index + openingMatch[0].length;
|
|
textCursor.advance(scriptStart);
|
|
const scriptLine = textCursor.lineNumber();
|
|
const scriptColumn = textCursor.columnNumber();
|
|
// Look for the closing </script> tag.
|
|
const closingMatch = SCRIPT_CLOSING_TAG.exec(content.substring(textCursor.offset()));
|
|
if (!closingMatch) {
|
|
break;
|
|
}
|
|
const scriptEnd = textCursor.offset() + closingMatch.index;
|
|
textCursor.advance(scriptEnd + closingMatch[0].length);
|
|
const scriptContent = content.substring(scriptStart, scriptEnd);
|
|
javaScriptOutline(scriptContent, ({chunk}) => {
|
|
chunk.forEach(item => {
|
|
if (item.line === 0) {
|
|
item.column += scriptColumn;
|
|
}
|
|
item.line += scriptLine;
|
|
});
|
|
chunkCallback({chunk, isLastChunk: false});
|
|
});
|
|
}
|
|
chunkCallback({chunk: [], isLastChunk: true});
|
|
}
|