Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 638665964
Change-Id: I7d6cce51b2ad9cf102dabb8a20a4819bfffdcd42
  • Loading branch information
12wrigja authored and copybara-github committed May 30, 2024
1 parent 45bf8bc commit 59ba8d1
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions common/third_party/tsetse/util/absolute_matcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as ts from 'typescript';

import {dealias, debugLog, isAllowlistedNamedDeclaration, isInStockLibraries} from './ast_tools';

const PATH_NAME_FORMAT = '[/\\.\\w\\d_-]+';
const JS_IDENTIFIER_FORMAT = '[\\w\\d_-]+';
import {
dealias,
debugLog,
isAllowlistedNamedDeclaration,
isInStockLibraries,
} from './ast_tools';

const PATH_NAME_FORMAT = '[/\\.\\w\\d_\\-$]+';
const JS_IDENTIFIER_FORMAT = '[\\w\\d_\\-$]+';
const FQN_FORMAT = `(${JS_IDENTIFIER_FORMAT}.)*${JS_IDENTIFIER_FORMAT}`;
const GLOBAL = 'GLOBAL';
const ANY_SYMBOL = 'ANY_SYMBOL';
Expand Down Expand Up @@ -83,7 +88,10 @@ export class AbsoluteMatcher {
readonly filePath: string;
readonly bannedName: string;

constructor(spec: string, readonly matchImport: boolean = false) {
constructor(
spec: string,
readonly matchImport: boolean = false,
) {
if (!spec.match(ABSOLUTE_RE)) {
throw new Error('Malformed matcher selector.');
}
Expand All @@ -96,9 +104,10 @@ export class AbsoluteMatcher {
// properties.
if (spec.match('.prototype.')) {
throw new Error(
'Your pattern includes a .prototype, but the AbsoluteMatcher is ' +
'Your pattern includes a .prototype, but the AbsoluteMatcher is ' +
'meant for non-object matches. Use the PropertyMatcher instead, or ' +
'the Property-based PatternKinds.');
'the Property-based PatternKinds.',
);
}

// Split spec by the separator "|".
Expand Down Expand Up @@ -136,8 +145,9 @@ export class AbsoluteMatcher {
const s = dealias(tc.getSymbolAtLocation(n), tc);
if (!s) {
debugLog(() => `cannot get symbol`);
return this.filePath === GLOBAL &&
matchGoogGlobal(n, this.bannedName, tc);
return (
this.filePath === GLOBAL && matchGoogGlobal(n, this.bannedName, tc)
);
}

// The TS-provided FQN tells us the full identifier, and the origin file
Expand Down

0 comments on commit 59ba8d1

Please sign in to comment.