File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Before starting make sure you have the following installed:
1616
1717- [ git] ( https://git-scm.com )
1818- [ Node] ( https://nodejs.org ) at LTS
19- - [ Yarn] ( https://yarnpkg.com ) at v1
19+ - [ Yarn] ( https://yarnpkg.com ) at v4 and/or enable corepack
2020- [ Rust] ( https://www.rust-lang.org/tools/install ) stable
2121- [ Flow] ( https://flow.org/en/docs/editors ) IDE autocompletion and type-checking
2222
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ type MacroAsset = {|
165165// NOTE: Make sure this is in sync with the TypeScript definition in the @parcel /macros package.
166166type MacroContext = { |
167167 addAsset ( asset : MacroAsset ) : void ,
168+ loc : SourceLocation ,
168169 invalidateOnFileChange ( FilePath ) : void ,
169170 invalidateOnFileCreate ( FileCreateInvalidation ) : void ,
170171 invalidateOnEnvChange ( string ) : void ,
@@ -544,6 +545,19 @@ export default (new Transformer({
544545 specifierType : 'esm' ,
545546 } ) ;
546547 } ,
548+ loc : {
549+ filePath : asset . filePath ,
550+ start : {
551+ line :
552+ loc . start_line + Number ( asset . meta . startLine ?? 1 ) - 1 ,
553+ column : loc . start_col ,
554+ } ,
555+ end : {
556+ line :
557+ loc . end_line + Number ( asset . meta . startLine ?? 1 ) - 1 ,
558+ column : loc . end_col ,
559+ } ,
560+ } ,
547561 invalidateOnFileChange ( filePath ) {
548562 asset . invalidateOnFileChange ( filePath ) ;
549563 } ,
Original file line number Diff line number Diff line change 11export interface MacroContext {
22 /** Adds an asset as a dependency of the JS module that called this macro. */
33 addAsset ( asset : MacroAsset ) : void ;
4+ /** The source location of the macro call. */
5+ loc : SourceLocation ;
46 /** Invalidate the macro call whenever the given file changes. */
57 invalidateOnFileChange ( filePath : string ) : void ;
68 /** Invalidate the macro call when a file matching the given pattern is created. */
@@ -13,6 +15,25 @@ export interface MacroContext {
1315 invalidateOnBuild ( ) : void ;
1416}
1517
18+ /**
19+ * Source locations are 1-based, meaning lines and columns start at 1
20+ */
21+ export type SourceLocation = {
22+ readonly filePath : string ;
23+
24+ /** inclusive */
25+ readonly start : {
26+ readonly line : number ;
27+ readonly column : number ;
28+ } ;
29+
30+ /** exclusive */
31+ readonly end : {
32+ readonly line : number ;
33+ readonly column : number ;
34+ } ;
35+ } ;
36+
1637export interface MacroAsset {
1738 /** The type of the asset (e.g. `'css'`). */
1839 type : string ;
You can’t perform that action at this time.
0 commit comments