Convert some .js files to typescript
* Rename some .js files to .ts
* Add minor fixes for eslint problems
* Add "export {};" line to files without imports and exports to mark
them as modules
* Updates server.go to handle imports without file extension correctly.
Change-Id: I4d4f1eaa689c6f351e64a2c3cfa4e8ac2d2e1f73
This commit is contained in:
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-ranged-comment-theme">
|
||||
@@ -38,4 +44,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-syntax-theme">
|
||||
@@ -118,4 +124,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import '@polymer/iron-icon/iron-icon.js';
|
||||
import '@polymer/iron-iconset-svg/iron-iconset-svg.js';
|
||||
import '@polymer/iron-icon/iron-icon';
|
||||
import '@polymer/iron-iconset-svg/iron-iconset-svg';
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<iron-iconset-svg name="gr-icons" size="24">
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="dashboard-header-styles">
|
||||
@@ -55,4 +61,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-change-list-styles">
|
||||
@@ -190,4 +196,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-change-metadata-shared-styles">
|
||||
@@ -55,4 +61,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-change-view-integration-shared-styles">
|
||||
@@ -70,4 +76,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-form-styles">
|
||||
@@ -124,4 +130,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-menu-page-styles">
|
||||
@@ -79,4 +85,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-page-nav-styles">
|
||||
@@ -72,4 +78,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-subpage-styles">
|
||||
@@ -42,4 +48,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-table-styles">
|
||||
@@ -116,4 +122,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="gr-voting-styles">
|
||||
@@ -40,4 +46,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `<dom-module id="shared-styles">
|
||||
@@ -127,7 +133,7 @@ $_documentContainer.innerHTML = `<dom-module id="shared-styles">
|
||||
--iron-icon-width: 20px;
|
||||
}
|
||||
|
||||
/* Stopgap solution until we remove hidden\$ attributes. */
|
||||
/* Stopgap solution until we remove hidden$ attributes. */
|
||||
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
@@ -196,4 +202,3 @@ document.head.appendChild($_documentContainer.content);
|
||||
from HTML and may be out of place here. Review them and
|
||||
then delete this comment!
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Mark the file as a module. Otherwise typescript assumes this is a script
|
||||
// and $_documentContainer is a global variable.
|
||||
// See: https://www.typescriptlang.org/docs/handbook/modules.html
|
||||
export {};
|
||||
|
||||
const $_documentContainer = document.createElement('template');
|
||||
|
||||
$_documentContainer.innerHTML = `
|
||||
@@ -223,4 +229,4 @@ $_documentContainer.innerHTML = `
|
||||
}
|
||||
</style></custom-style>`;
|
||||
|
||||
document.head.appendChild($_documentContainer.content);
|
||||
document.head.appendChild($_documentContainer.content);
|
||||
@@ -167,8 +167,18 @@ func handleSrcRequest(compiledSrcPath string, dirListingMux *http.ServeMux, writ
|
||||
// with the import error, so we can catch this problem easily.
|
||||
writer.Header().Set("Content-Type", "text/html")
|
||||
} else if isJsFile {
|
||||
moduleImportRegexp := regexp.MustCompile("(?m)^(import.*)'([^/.].*)';$")
|
||||
data = moduleImportRegexp.ReplaceAll(data, []byte("$1 '/node_modules/$2';"))
|
||||
// The following code updates import statements.
|
||||
// 1. Keep all imports started with '.' character unchanged (i.e. all relative
|
||||
// imports like import ... from './a.js' or import ... from '../b/c/d.js'
|
||||
// 2. For other imports it adds '/node_modules/' prefix. Additionally,
|
||||
// if an in imported file has .js or .mjs extension, the code keeps
|
||||
// the file extension unchanged. Otherwise, it adds .js extension.
|
||||
// Examples:
|
||||
// '@polymer/polymer.js' -> '/node_modules/@polymer/polymer.js'
|
||||
// 'page/page.mjs' -> '/node_modules/page.mjs'
|
||||
// '@polymer/iron-icon' -> '/node_modules/@polymer/iron-icon.js'
|
||||
moduleImportRegexp := regexp.MustCompile("(?m)^(import.*)'([^/.].*?)(\\.(m?)js)?';$")
|
||||
data = moduleImportRegexp.ReplaceAll(data, []byte("$1 '/node_modules/$2.${4}js';"))
|
||||
writer.Header().Set("Content-Type", "application/javascript")
|
||||
} else if strings.HasSuffix(normalizedContentPath, ".css") {
|
||||
writer.Header().Set("Content-Type", "text/css")
|
||||
|
||||
Reference in New Issue
Block a user