@@ -11,7 +11,7 @@ const gzipInline = function(data) {
1111 if ( data instanceof Map ) {
1212 return `new Map(${ gzipInline ( [ ...data ] ) } )` ;
1313 }
14- const json = jsesc ( data , { 'json' : true } ) ;
14+ const json = JSON . stringify ( data ) ;
1515 const gzipBuffer = zlib . gzipSync ( json ) ;
1616 const str = gzipBuffer . toString ( 'base64' ) ;
1717 return `JSON.parse(require('zlib').gunzipSync(Buffer.from('${ str } ','base64')))` ;
@@ -84,7 +84,13 @@ const writeFiles = function(options) {
8484 return ;
8585 }
8686 const dirMap = { } ;
87- const bidiMirroringGlyphMap = [ ] ;
87+ /**
88+ * A list of flatten (x, y) pairs,
89+ * where x is a codepoint, y := codepoint(z) - x,
90+ * where z is the BidiMirroringGlyph of character(x) and codepoint(z) > x
91+ * @type number[]
92+ */
93+ const bidiMirroringGlyphFlatPairs = [ ] ;
8894 const auxMap = { } ;
8995 Object . keys ( map ) . forEach ( function ( item ) {
9096 const codePoints = map [ item ] ;
@@ -112,10 +118,11 @@ const writeFiles = function(options) {
112118 )
113119 ) {
114120 if ( type == 'Bidi_Mirroring_Glyph' ) {
115- const shortName = item . codePointAt ( 0 ) ;
121+ const toCodepoint = item . codePointAt ( 0 ) ;
116122 codePoints . toArray ( ) . forEach ( function ( codePoint ) {
117- console . assert ( ! bidiMirroringGlyphMap [ codePoint ] ) ;
118- bidiMirroringGlyphMap [ codePoint ] = shortName ;
123+ if ( codePoint < toCodepoint ) {
124+ bidiMirroringGlyphFlatPairs . push ( codePoint , toCodepoint - codePoint ) ;
125+ }
119126 } ) ;
120127 } else {
121128 if ( ! auxMap [ type ] ) {
@@ -124,34 +131,7 @@ const writeFiles = function(options) {
124131 auxMap [ type ] . push ( [ item , codePoints ] ) ;
125132 }
126133 }
127- if ( isNamesCanon ) {
128- return ;
129- }
130-
131- if ( type == 'Bidi_Mirroring_Glyph' ) {
132- const dir = path . resolve (
133- __dirname , '..' ,
134- 'output' , 'unicode-' + version , type
135- ) ;
136- if ( ! hasKey ( dirMap , type ) ) {
137- dirMap [ type ] = [ ] ;
138- }
139- fs . mkdirSync ( dir , { recursive : true } ) ;
140- // `Bidi_Mirroring_Glyph/index.js`
141- // Note: `Bidi_Mirroring_Glyph` doesn’t have repeated strings; don’t gzip.
142- const flatPairs = bidiMirroringGlyphMap
143- . flatMap ( ( a , b ) => a < b ? [ a , b - a ] : [ ] ) ;
144- const output = [
145- `const chr=String.fromCodePoint` ,
146- `const pair=(t,u,v)=>[t?u+v:v,chr(t?u:u+v)]` ,
147- `module.exports=new Map(${
148- jsesc ( flatPairs )
149- } .map((v,i,a)=>pair(i&1,a[i^1],v)))`
150- ] . join ( ';' ) ;
151- fs . writeFileSync (
152- path . resolve ( dir , 'index.js' ) ,
153- output
154- ) ;
134+ if ( isNamesCanon || type == 'Bidi_Mirroring_Glyph' ) {
155135 return ;
156136 }
157137
@@ -211,6 +191,31 @@ const writeFiles = function(options) {
211191 `module.exports=${ symbolsExports } `
212192 ) ;
213193 } ) ;
194+ if ( options . type == 'Bidi_Mirroring_Glyph' ) {
195+ const type = options . type ;
196+ const dir = path . resolve (
197+ __dirname , '..' ,
198+ 'output' , 'unicode-' + version , type
199+ ) ;
200+ if ( ! hasKey ( dirMap , type ) ) {
201+ dirMap [ type ] = [ ] ;
202+ }
203+ fs . mkdirSync ( dir , { recursive : true } ) ;
204+ // `Bidi_Mirroring_Glyph/index.js`
205+ // Note: `Bidi_Mirroring_Glyph` doesn’t have repeated strings; don’t gzip.
206+ const output = [
207+ `const chr=String.fromCodePoint` ,
208+ `const pair=(t,u,v)=>[t?u+v:v,chr(t?u:u+v)]` ,
209+ `module.exports=new Map(${
210+ JSON . stringify ( bidiMirroringGlyphFlatPairs )
211+ } .map((v,i,a)=>pair(i&1,a[i^1],v)))`
212+ ] . join ( ';' ) ;
213+ fs . writeFileSync (
214+ path . resolve ( dir , 'index.js' ) ,
215+ output
216+ ) ;
217+ return ;
218+ }
214219 Object . keys ( auxMap ) . forEach ( function ( type ) {
215220 const dir = path . resolve (
216221 __dirname , '..' ,
0 commit comments