-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add url dependency for serviceWorker.register calls (#398)
* Add url dependency for serviceWorker.register calls * extract matchesPattern helper * sync SW regexp with matchesPattern arg
- Loading branch information
1 parent
d763a1a
commit 0ab0aca
Showing
7 changed files
with
77 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const types = require('babel-types'); | ||
|
||
// from babel-types. remove when we upgrade to babel 7. | ||
// https://github.com/babel/babel/blob/0189b387026c35472dccf45d14d58312d249f799/packages/babel-types/src/index.js#L347 | ||
module.exports = function matchesPattern(member, match, allowPartial) { | ||
// not a member expression | ||
if (!types.isMemberExpression(member)) return false; | ||
|
||
const parts = Array.isArray(match) ? match : match.split('.'); | ||
const nodes = []; | ||
|
||
let node; | ||
for (node = member; types.isMemberExpression(node); node = node.object) { | ||
nodes.push(node.property); | ||
} | ||
nodes.push(node); | ||
|
||
if (nodes.length < parts.length) return false; | ||
if (!allowPartial && nodes.length > parts.length) return false; | ||
|
||
for (let i = 0, j = nodes.length - 1; i < parts.length; i++, j--) { | ||
const node = nodes[j]; | ||
let value; | ||
if (types.isIdentifier(node)) { | ||
value = node.name; | ||
} else if (types.isStringLiteral(node)) { | ||
value = node.value; | ||
} else { | ||
return false; | ||
} | ||
|
||
if (parts[i] !== value) return false; | ||
} | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
navigator.serviceWorker.register('worker.js', { scope: './' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
self.addEventListener('message', () => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters