@@ -18,6 +18,15 @@ const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/;
1818// TODO: Handle multiline imports?
1919const RE_REQUIRE = / c o n s t { ( .+ ?) } = r e q u i r e \( ( .+ ?) \) / ;
2020
21+ // Regex for ref docs URLs
22+ // eg. "https://firebase.google.com/docs/reference/js/v8/firebase.User"
23+ const RE_REF_DOCS = / h t t p s : \/ \/ f i r e b a s e \. g o o g l e \. c o m \/ d o c s \/ r e f e r e n c e \/ j s \/ ( .* ) / ;
24+
25+ // Maps v8 ref docs URLs to their v9 counterpart
26+ const REF_DOCS_MAPPINGS : { [ key : string ] : string } = {
27+ "v8/firebase.User" : "auth.user"
28+ } ;
29+
2130type SnippetsConfig = {
2231 enabled : boolean ;
2332 suffix : string ;
@@ -30,6 +39,23 @@ function isBlank(line: string) {
3039 return line . trim ( ) . length === 0 ;
3140}
3241
42+ /**
43+ * Replace all v8 ref doc urls with their v9 counterpart.
44+ */
45+ function replaceRefDocsUrls ( lines : string [ ] ) {
46+ const outputLines = [ ] ;
47+ for ( const line of lines ) {
48+ if ( line . match ( RE_REF_DOCS ) ) {
49+ outputLines . push ( line . replace ( RE_REF_DOCS , ( match : string , p1 ?: string ) => {
50+ return p1 ? `https://firebase.google.com/docs/reference/js/${ REF_DOCS_MAPPINGS [ p1 ] } ` : match ;
51+ } ) ) ;
52+ } else {
53+ outputLines . push ( line ) ;
54+ }
55+ }
56+ return outputLines ;
57+ }
58+
3359/**
3460 * Replace all const { foo } = require('bar') with import { foo } from 'bar';
3561 */
@@ -119,6 +145,7 @@ function processSnippet(
119145 outputLines = addSuffixToSnippetNames ( outputLines , snippetSuffix ) ;
120146 outputLines = adjustIndentation ( outputLines ) ;
121147 outputLines = removeFirstLineAfterComments ( outputLines ) ;
148+ outputLines = replaceRefDocsUrls ( outputLines ) ;
122149
123150 // Add a preamble to every snippet
124151 const preambleLines = [
0 commit comments