File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 7
7
8
8
const ObjectMiddleware = require ( "../serialization/ObjectMiddleware" ) ;
9
9
10
+ const Position = /** @type {TODO } */ ( require ( "acorn" ) ) . Position ;
10
11
const SourceLocation = require ( "acorn" ) . SourceLocation ;
11
12
const CachedSource = require ( "webpack-sources" ) . CachedSource ;
12
13
const ConcatSource = require ( "webpack-sources" ) . ConcatSource ;
@@ -17,6 +18,7 @@ const ReplaceSource = require("webpack-sources").ReplaceSource;
17
18
const SourceMapSource = require ( "webpack-sources" ) . SourceMapSource ;
18
19
19
20
/** @typedef {import("../Dependency").RealDependencyLocation } RealDependencyLocation */
21
+ /** @typedef {import("../Dependency").SourcePosition } SourcePosition */
20
22
21
23
const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer" ;
22
24
@@ -234,6 +236,34 @@ ObjectMiddleware.register(
234
236
} ( )
235
237
) ;
236
238
239
+ ObjectMiddleware . register (
240
+ Position ,
241
+ CURRENT_MODULE ,
242
+ "acorn/Position" ,
243
+ new class PositionSerializer {
244
+ /**
245
+ * @param {Position } pos the position to be serialized
246
+ * @param {ObjectMiddleware.ObjectSerializerContext } context context
247
+ * @returns {void }
248
+ */
249
+ serialize ( pos , { write } ) {
250
+ write ( pos . line ) ;
251
+ write ( pos . column ) ;
252
+ }
253
+
254
+ /**
255
+ * @param {ObjectMiddleware.ObjectDeserializerContext } context context
256
+ * @returns {SourcePosition } position
257
+ */
258
+ deserialize ( { read } ) {
259
+ return {
260
+ line : read ( ) ,
261
+ column : read ( )
262
+ } ;
263
+ }
264
+ } ( )
265
+ ) ;
266
+
237
267
ObjectMiddleware . register (
238
268
SourceMapSource ,
239
269
CURRENT_MODULE ,
Original file line number Diff line number Diff line change @@ -82,12 +82,12 @@ const schema = [
82
82
} ,
83
83
{
84
84
title : "imports" ,
85
- regexp : / ( c o n s t ( \{ \s + \w + ( , \s + \w + ) * \s + \} | \w + ) = r e q u i r e \( " [ ^ " ] + " \) ( \. \w + ) * ; \n ) + \n / g,
85
+ regexp : / ( c o n s t ( \{ \s + \w + ( , \s + \w + ) * \s + \} | \w + ) = ( \/ \* \* @ t y p e \{ T O D O \} \* \/ \s \( ) ? r e q u i r e \( " [ ^ " ] + " \) \) ? ( \. \w + ) * ; \n ) + \n / g,
86
86
updateMessage : "sort imports alphabetically" ,
87
87
update ( content ) {
88
88
const items = execToArray (
89
89
content ,
90
- / c o n s t (?: \{ \s + \w + (?: , \s + \w + ) * \s + \} | \w + ) = r e q u i r e \( " ( [ ^ " ] + ) " \) ( (?: \. \w + ) * ) ; \n / g
90
+ / c o n s t (?: \{ \s + \w + (?: , \s + \w + ) * \s + \} | \w + ) = (?: \/ \* \* @ t y p e \{ T O D O \} \* \/ \s \( ) ? r e q u i r e \( " ( [ ^ " ] + ) " \) \) ? ( (?: \. \w + ) * ) ; \n / g
91
91
) ;
92
92
items . sort ( sortImport ) ;
93
93
return items . map ( item => item . content ) . join ( "" ) + "\n" ;
You can’t perform that action at this time.
0 commit comments