-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid file name collisions from converted HTML files (#269)
* Convert javascript imports as inline module code in modules * update tests * handle for package layout as well * code cleanup * Add import references to a11ySuite in tests (#270) * Add import references to a11ySuite in tests * add TODO * document converter NOTE
- Loading branch information
1 parent
be701bc
commit fc040b2
Showing
13 changed files
with
206 additions
and
45 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
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,51 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved. | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* The complete set of authors may be found at | ||
* http://polymer.github.io/AUTHORS.txt | ||
* The complete set of contributors may be found at | ||
* http://polymer.github.io/CONTRIBUTORS.txt | ||
* Code distributed by Google as part of the polymer project is also | ||
* subject to an additional IP rights grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
|
||
import * as astTypes from 'ast-types'; | ||
import {NodePath} from 'ast-types'; | ||
import * as estree from 'estree'; | ||
import * as jsc from 'jscodeshift'; | ||
|
||
/** | ||
* Rewrite references in a program from their original names to the local names | ||
* based on the new named exports system. | ||
* | ||
* TODO(fks): This standalone A11ySuite handling could be brought into normal | ||
* `collectNamespacedReferences()` logic if we added `A11ySuite()` to the known | ||
* export graph. | ||
*/ | ||
export function addA11ySuiteIfUsed( | ||
program: estree.Program, a11ySuiteUrl: string): boolean { | ||
let isFound = false; | ||
astTypes.visit(program, { | ||
visitCallExpression(path: NodePath<estree.CallExpression>) { | ||
const callee = path.node.callee as estree.Identifier; | ||
const name = callee.name; | ||
if (name === 'a11ySuite') { | ||
isFound = true; | ||
this.abort(); | ||
} | ||
this.traverse(path); | ||
} | ||
}); | ||
|
||
if (!isFound) { | ||
return false; | ||
} | ||
|
||
program.body.unshift(jsc.importDeclaration( | ||
[jsc.importSpecifier(jsc.identifier('a11ySuite'))], | ||
jsc.literal(a11ySuiteUrl))); | ||
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
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
Oops, something went wrong.