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:
16
16
17
17
- [ git] ( https://git-scm.com )
18
18
- [ Node] ( https://nodejs.org ) at LTS
19
- - [ Yarn] ( https://yarnpkg.com ) at v1
19
+ - [ Yarn] ( https://yarnpkg.com ) at v4 and/or enable corepack
20
20
- [ Rust] ( https://www.rust-lang.org/tools/install ) stable
21
21
- [ Flow] ( https://flow.org/en/docs/editors ) IDE autocompletion and type-checking
22
22
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ type MacroAsset = {|
165
165
// NOTE: Make sure this is in sync with the TypeScript definition in the @parcel /macros package.
166
166
type MacroContext = { |
167
167
addAsset ( asset : MacroAsset ) : void ,
168
+ loc : SourceLocation ,
168
169
invalidateOnFileChange ( FilePath ) : void ,
169
170
invalidateOnFileCreate ( FileCreateInvalidation ) : void ,
170
171
invalidateOnEnvChange ( string ) : void ,
@@ -544,6 +545,19 @@ export default (new Transformer({
544
545
specifierType : 'esm' ,
545
546
} ) ;
546
547
} ,
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
+ } ,
547
561
invalidateOnFileChange ( filePath ) {
548
562
asset . invalidateOnFileChange ( filePath ) ;
549
563
} ,
Original file line number Diff line number Diff line change 1
1
export interface MacroContext {
2
2
/** Adds an asset as a dependency of the JS module that called this macro. */
3
3
addAsset ( asset : MacroAsset ) : void ;
4
+ /** The source location of the macro call. */
5
+ loc : SourceLocation ;
4
6
/** Invalidate the macro call whenever the given file changes. */
5
7
invalidateOnFileChange ( filePath : string ) : void ;
6
8
/** Invalidate the macro call when a file matching the given pattern is created. */
@@ -13,6 +15,25 @@ export interface MacroContext {
13
15
invalidateOnBuild ( ) : void ;
14
16
}
15
17
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
+
16
37
export interface MacroAsset {
17
38
/** The type of the asset (e.g. `'css'`). */
18
39
type : string ;
You can’t perform that action at this time.
0 commit comments