Convert punycode.js into an ES module (#3845)

This commit is contained in:
Manish Jethani 2021-08-22 21:33:59 +05:30 committed by GitHub
parent 73ae06230b
commit 9ddbb293c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 24 additions and 63 deletions

View File

@ -24,7 +24,7 @@
/******************************************************************************/ /******************************************************************************/
import './lib/publicsuffixlist/publicsuffixlist.js'; import './lib/publicsuffixlist/publicsuffixlist.js';
import './lib/punycode.js'; import punycode from './lib/punycode.js';
import globals from './js/globals.js'; import globals from './js/globals.js';
import staticNetFilteringEngine from './js/static-net-filtering.js'; import staticNetFilteringEngine from './js/static-net-filtering.js';
@ -93,7 +93,7 @@ function pslInit(raw) {
console.info('Unable to populate public suffix list'); console.info('Unable to populate public suffix list');
return; return;
} }
globals.publicSuffixList.parse(raw, globals.punycode.toASCII); globals.publicSuffixList.parse(raw, punycode.toASCII);
console.info('Public suffix list populated'); console.info('Public suffix list populated');
} }

View File

@ -33,7 +33,7 @@ import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url)); const __dirname = dirname(fileURLToPath(import.meta.url));
import './lib/punycode.js'; import punycode from './lib/punycode.js';
import './lib/publicsuffixlist/publicsuffixlist.js'; import './lib/publicsuffixlist/publicsuffixlist.js';
import globals from './js/globals.js'; import globals from './js/globals.js';
@ -77,7 +77,7 @@ async function enableWASM() {
function pslInit(raw) { function pslInit(raw) {
if ( typeof raw === 'string' && raw.trim() !== '' ) { if ( typeof raw === 'string' && raw.trim() !== '' ) {
globals.publicSuffixList.parse(raw, globals.punycode.toASCII); globals.publicSuffixList.parse(raw, punycode.toASCII);
return globals.publicSuffixList; return globals.publicSuffixList;
} }
@ -105,7 +105,7 @@ function pslInit(raw) {
console.error('Unable to populate public suffix list'); console.error('Unable to populate public suffix list');
return; return;
} }
globals.publicSuffixList.parse(raw, globals.punycode.toASCII); globals.publicSuffixList.parse(raw, punycode.toASCII);
return globals.publicSuffixList; return globals.publicSuffixList;
} }

View File

@ -23,7 +23,8 @@
/******************************************************************************/ /******************************************************************************/
import globals from './globals.js'; import punycode from '../lib/punycode.js';
import { LineIterator } from './text-utils.js'; import { LineIterator } from './text-utils.js';
import { import {
@ -33,8 +34,6 @@ import {
/******************************************************************************/ /******************************************************************************/
const punycode = globals.punycode || undefined;
// Object.create(null) is used below to eliminate worries about unexpected // Object.create(null) is used below to eliminate worries about unexpected
// property names in prototype chain -- and this way we don't have to use // property names in prototype chain -- and this way we don't have to use
// hasOwnProperty() to avoid this. // hasOwnProperty() to avoid this.

View File

@ -25,13 +25,13 @@
/******************************************************************************/ /******************************************************************************/
import globals from './globals.js'; import punycode from '../lib/punycode.js';
import { decomposeHostname } from './uri-utils.js'; import { decomposeHostname } from './uri-utils.js';
import { LineIterator } from './text-utils.js'; import { LineIterator } from './text-utils.js';
/******************************************************************************/ /******************************************************************************/
const punycode = globals.punycode || undefined;
const decomposedSource = []; const decomposedSource = [];
// Object.create(null) is used below to eliminate worries about unexpected // Object.create(null) is used below to eliminate worries about unexpected

View File

@ -24,7 +24,7 @@
/******************************************************************************/ /******************************************************************************/
import '../lib/publicsuffixlist/publicsuffixlist.js'; import '../lib/publicsuffixlist/publicsuffixlist.js';
import '../lib/punycode.js'; import punycode from '../lib/punycode.js';
import cacheStorage from './cachestorage.js'; import cacheStorage from './cachestorage.js';
import cosmeticFilteringEngine from './cosmetic-filtering.js'; import cosmeticFilteringEngine from './cosmetic-filtering.js';
@ -1087,7 +1087,6 @@ const getLists = async function(callback) {
// TODO: also return origin of embedded frames? // TODO: also return origin of embedded frames?
const getOriginHints = function() { const getOriginHints = function() {
const punycode = globals.punycode;
const out = new Set(); const out = new Set();
for ( const tabId of µb.pageStores.keys() ) { for ( const tabId of µb.pageStores.keys() ) {
if ( tabId === -1 ) { continue; } if ( tabId === -1 ) { continue; }

View File

@ -19,10 +19,12 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global punycode, uDom */ /* global uDom */
'use strict'; 'use strict';
import punycode from '../lib/punycode.js';
/******************************************************************************/ /******************************************************************************/
{ {

View File

@ -19,10 +19,12 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* global punycode, uDom */ /* global uDom */
'use strict'; 'use strict';
import punycode from '../lib/punycode.js';
/******************************************************************************/ /******************************************************************************/
(( ) => { (( ) => {

View File

@ -24,7 +24,7 @@
/******************************************************************************/ /******************************************************************************/
import '../lib/publicsuffixlist/publicsuffixlist.js'; import '../lib/publicsuffixlist/publicsuffixlist.js';
import '../lib/punycode.js'; import punycode from '../lib/punycode.js';
import cosmeticFilteringEngine from './cosmetic-filtering.js'; import cosmeticFilteringEngine from './cosmetic-filtering.js';
import globals from './globals.js'; import globals from './globals.js';
@ -1244,7 +1244,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
µb.compilePublicSuffixList = function(content) { µb.compilePublicSuffixList = function(content) {
const psl = globals.publicSuffixList; const psl = globals.publicSuffixList;
psl.parse(content, globals.punycode.toASCII); psl.parse(content, punycode.toASCII);
io.put(`compiled/${this.pslAssetKey}`, psl.toSelfie(sparseBase64)); io.put(`compiled/${this.pslAssetKey}`, psl.toSelfie(sparseBase64));
}; };

View File

@ -24,7 +24,7 @@
/******************************************************************************/ /******************************************************************************/
import '../lib/publicsuffixlist/publicsuffixlist.js'; import '../lib/publicsuffixlist/publicsuffixlist.js';
import '../lib/punycode.js'; import punycode from '../lib/punycode.js';
import globals from './globals.js'; import globals from './globals.js';
@ -34,7 +34,6 @@ import globals from './globals.js';
// https://github.com/gorhill/uBlock/blob/8b5733a58d3acf9fb62815e14699c986bd1c2fdc/src/js/uritools.js // https://github.com/gorhill/uBlock/blob/8b5733a58d3acf9fb62815e14699c986bd1c2fdc/src/js/uritools.js
const psl = globals.publicSuffixList; const psl = globals.publicSuffixList;
const punycode = globals.punycode;
const reCommonHostnameFromURL = const reCommonHostnameFromURL =
/^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//; /^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//;

View File

@ -1,20 +1,5 @@
/*! https://mths.be/punycode v1.3.2 by @mathias */ /*! https://mths.be/punycode v1.3.2 by @mathias */
;(function(root) { export default (function() {
/** Detect free variables */
var freeExports = typeof exports == 'object' && exports &&
!exports.nodeType && exports;
var freeModule = typeof module == 'object' && module &&
!module.nodeType && module;
var freeGlobal = typeof global == 'object' && global || self;
if (
freeGlobal.global === freeGlobal ||
freeGlobal.window === freeGlobal ||
freeGlobal.self === freeGlobal
) {
root = freeGlobal;
}
/** /**
* The `punycode` object. * The `punycode` object.
* @name punycode * @name punycode
@ -504,27 +489,5 @@
'toUnicode': toUnicode 'toUnicode': toUnicode
}; };
/** Expose `punycode` */ return punycode;
// Some AMD build optimizers, like r.js, check for specific condition patterns })();
// like the following:
if (
typeof define == 'function' &&
typeof define.amd == 'object' &&
define.amd
) {
define('punycode', function() {
return punycode;
});
} else if (freeExports && freeModule) {
if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+
freeModule.exports = punycode;
} else { // in Narwhal or RingoJS v0.7.0-
for (key in punycode) {
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
}
}
} else { // in Rhino or a web browser
root.punycode = punycode;
}
}(this));

View File

@ -96,13 +96,12 @@
</div> </div>
<script src="js/fa-icons.js"></script> <script src="js/fa-icons.js"></script>
<script src="lib/punycode.js"></script>
<script src="js/vapi.js"></script> <script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script> <script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script> <script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script> <script src="js/udom.js"></script>
<script src="js/i18n.js"></script> <script src="js/i18n.js"></script>
<script src="js/popup-fenix.js"></script> <script src="js/popup-fenix.js" type="module"></script>
</body> </body>

View File

@ -62,13 +62,12 @@
</div> </div>
<script src="js/fa-icons.js"></script> <script src="js/fa-icons.js"></script>
<script src="lib/punycode.js"></script>
<script src="js/vapi.js"></script> <script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script> <script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script> <script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script> <script src="js/udom.js"></script>
<script src="js/i18n.js"></script> <script src="js/i18n.js"></script>
<script src="js/popup.js"></script> <script src="js/popup.js" type="module"></script>
</body> </body>

View File

@ -43,7 +43,6 @@
<script src="lib/codemirror/addon/scroll/annotatescrollbar.js"></script> <script src="lib/codemirror/addon/scroll/annotatescrollbar.js"></script>
<script src="lib/codemirror/addon/search/searchcursor.js"></script> <script src="lib/codemirror/addon/search/searchcursor.js"></script>
<script src="lib/codemirror/addon/selection/active-line.js"></script> <script src="lib/codemirror/addon/selection/active-line.js"></script>
<script src="lib/punycode.js"></script>
<script src="js/codemirror/search.js"></script> <script src="js/codemirror/search.js"></script>
<script src="js/codemirror/search-thread.js"></script> <script src="js/codemirror/search-thread.js"></script>