Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Incremental DOM Support #549

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions closure/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def rules_closure_dependencies(
omit_args4j = False,
omit_bazel_skylib = False,
omit_clang = False,
omit_com_google_angular_tsickle_tslib = False,
omit_com_google_auto_common = False,
omit_com_google_auto_factory = False,
omit_com_google_auto_value = False,
Expand All @@ -54,12 +55,14 @@ def rules_closure_dependencies(
omit_com_google_jsinterop_annotations = False,
omit_com_google_protobuf = False,
omit_com_google_protobuf_js = False,
omit_com_google_closure_templates = False,
omit_com_google_template_soy = False,
omit_com_google_template_soy_jssrc = False,
omit_com_ibm_icu_icu4j = False,
omit_com_squareup_javapoet = False,
omit_fonts_noto_hinted_deb = False,
omit_fonts_noto_mono_deb = False,
omit_incremental_dom = False,
omit_javax_annotation_jsr250_api = False,
omit_javax_inject = False,
omit_libexpat_amd64_deb = False,
Expand Down Expand Up @@ -89,6 +92,8 @@ def rules_closure_dependencies(
bazel_skylib()
if not omit_clang:
clang()
if not omit_com_google_angular_tsickle_tslib:
com_google_angular_tsickle_tslib()
if not omit_com_google_auto_common:
com_google_auto_common()
if not omit_com_google_auto_factory:
Expand Down Expand Up @@ -139,6 +144,8 @@ def rules_closure_dependencies(
com_google_protobuf()
if not omit_com_google_protobuf_js:
com_google_protobuf_js()
if not omit_com_google_closure_templates:
com_google_closure_templates()
if not omit_com_google_template_soy:
com_google_template_soy()
if not omit_com_google_template_soy_jssrc:
Expand All @@ -151,6 +158,8 @@ def rules_closure_dependencies(
fonts_noto_hinted_deb()
if not omit_fonts_noto_mono_deb:
fonts_noto_mono_deb()
if not omit_incremental_dom:
incremental_dom()
if not omit_javax_annotation_jsr250_api:
javax_annotation_jsr250_api()
if not omit_javax_inject:
Expand Down Expand Up @@ -240,6 +249,17 @@ def clang():
macos_sha256 = "633a833396bf2276094c126b072d52b59aca6249e7ce8eae14c728016edb5e61",
)

def com_google_angular_tsickle_tslib():
http_archive(
name = "com_google_angular_tsickle_tslib",
sha256 = "41f9692b4d9af0bab343457aaa4b7619a84618570cd24039e093223a2971cc89",
strip_prefix = "tsickle-e482bc9fd3be72191bafdd23afaab2c8e83787a0/third_party/tslib",
build_file = "@io_bazel_rules_closure//closure/templates:soy_tslib.BUILD",
urls = [
"https://github.com/angular/tsickle/archive/e482bc9fd3be72191bafdd23afaab2c8e83787a0.tar.gz",
],
)

def com_google_auto_common():
java_import_external(
name = "com_google_auto_common",
Expand Down Expand Up @@ -748,6 +768,16 @@ def com_google_protobuf_js():
],
)

def com_google_closure_templates():
http_archive(
name = "com_google_closure_templates",
sha256 = "b8863e45841cb89e9c1e29d46eaabfb4599724d85ef081dbb6f9dfc6ffc58c99",
strip_prefix = "closure-templates-a1c02e60ae88ed1b7db92722ea25ac7d396514fc",
urls = [
"https://github.com/google/closure-templates/archive/a1c02e60ae88ed1b7db92722ea25ac7d396514fc.tar.gz",
],
)

def com_google_template_soy():
java_import_external(
name = "com_google_template_soy",
Expand Down Expand Up @@ -786,6 +816,12 @@ def com_google_template_soy():
"SoyToJbcSrcCompiler",
"SoyToJsSrcCompiler",
"SoyToPySrcCompiler",
"SoyToIncrementalDomSrcCompiler",
"SoyMsgExtractor",
"SoyHeaderCompiler",
"SoyConformanceChecker",
"SoyPluginValidator",
"SoyVeMetadataGenerator",
)
]),
)
Expand Down Expand Up @@ -842,6 +878,16 @@ def fonts_noto_mono_deb():
sha256 = "71ff715cf50a74a8cc11b02e7c906b69a242d3d677e739e0b2d18cd23b7de375",
)

def incremental_dom():
http_archive(
name = "incremental_dom",
sha256 = "33b060bb04c38b4c5c9c203de702dcbc482128be0cead6c5e9e9658dfae8b715",
strip_prefix = "incremental-dom-a6c91ebc569110993c7c4130f0456504f624459a",
urls = [
"https://github.com/tabspring/incremental-dom/archive/a6c91ebc569110993c7c4130f0456504f624459a.tar.gz",
],
)

def javax_annotation_jsr250_api():
java_import_external(
name = "javax_annotation_jsr250_api",
Expand Down
41 changes: 40 additions & 1 deletion closure/templates/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0

load("@rules_java//java:defs.bzl", "java_library")
load("//closure:defs.bzl", "closure_js_library", "closure_js_proto_library")
load("//closure:defs.bzl", "closure_js_library", "closure_js_proto_library", "closure_proto_library")

java_library(
name = "templates",
Expand All @@ -29,12 +29,18 @@ closure_js_proto_library(
srcs = ["@com_google_common_html_types_html_proto//file"],
)

closure_proto_library(
name = "soy_ve_metadata_proto",
deps = ["@com_google_closure_templates//src/main/protobuf:ve_metadata_proto"],
)

closure_js_library(
name = "soy_jssrc",
srcs = ["@com_google_template_soy_jssrc"],
lenient = True,
deps = [
":soy_html_proto",
"//closure/protobuf:jspb",
"@com_google_javascript_closure_library//closure/goog/array",
"@com_google_javascript_closure_library//closure/goog/asserts",
"@com_google_javascript_closure_library//closure/goog/debug",
Expand All @@ -59,6 +65,39 @@ closure_js_library(
],
)

closure_js_library(
name = "soy_idom",
srcs = ["@com_google_template_soy_jssrc//:idom"],
lenient = True,
deps = [
":soy_tslib",
":soy_jssrc",
":soy_html_proto",
":soy_ve_metadata_proto",
"//closure/protobuf:jspb",
"@com_google_javascript_closure_library//closure/goog/asserts",
"@com_google_javascript_closure_library//closure/goog/soy",
"@com_google_javascript_closure_library//closure/goog/soy:data",
"@com_google_javascript_closure_library//closure/goog/string",
"@incremental_dom//closure",
],
suppress = [
"nonStandardJsDocs",
],
)

closure_js_library(
name = "soy_tslib",
srcs = [
"soy_tslib.js",
"@com_google_angular_tsickle_tslib//:tslib",
],
lenient = True,
deps = [
# None.
],
)

java_library(
name = "safe_html_types",
exports = ["@com_google_common_html_types"],
Expand Down
29 changes: 24 additions & 5 deletions closure/templates/closure_js_template_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ load("//closure/private:defs.bzl", "SOY_FILE_TYPE", "unfurl")
load("//closure/templates:closure_templates_plugin.bzl", "SoyPluginInfo")

_SOYTOJSSRCCOMPILER = "@com_google_template_soy//:SoyToJsSrcCompiler"
_SOYIDOMCOMPILER = "@com_google_template_soy//:SoyToIncrementalDomSrcCompiler"

_IDOM_DEPS = [
str(Label("//closure/templates:soy_idom")),
str(Label("//closure/templates:soy_tslib")),
]

def _impl(ctx):
args = ["--outputPathFormat=%s/{INPUT_DIRECTORY}/{INPUT_FILE_NAME}.js" %
Expand All @@ -29,7 +35,7 @@ def _impl(ctx):
args += ["--googMsgsAreExternal"]
if ctx.attr.should_generate_soy_msg_defs:
args += ["--shouldGenerateGoogMsgDefs"]
if ctx.attr.bidi_global_dir:
if (not ctx.attr.idom) and ctx.attr.bidi_global_dir:
args += ["--bidiGlobalDir=%s" % ctx.attr.bidi_global_dir]
if ctx.attr.plugins:
args += ["--pluginModules=%s" % ",".join([
Expand Down Expand Up @@ -89,6 +95,7 @@ _closure_js_template_library = rule(
"should_generate_soy_msg_defs": attr.bool(),
"bidi_global_dir": attr.int(default = 1, values = [1, -1]),
"soy_msgs_are_external": attr.bool(),
"idom": attr.bool(),
"compiler": attr.label(cfg = "host", executable = True, mandatory = True),
"defs": attr.string_list(),
},
Expand All @@ -106,8 +113,12 @@ def closure_js_template_library(
bidi_global_dir = None,
soy_msgs_are_external = None,
defs = [],
jsdeps = [],
idom = False,
compiler = None,
**kwargs):
compiler = str(Label(_SOYTOJSSRCCOMPILER))
default_compiler = (idom and str(Label(_SOYIDOMCOMPILER))) or str(Label(_SOYTOJSSRCCOMPILER))
resolved_compiler = compiler or default_compiler
js_srcs = [src + ".js" for src in srcs]
_closure_js_template_library(
name = name + "_soy_js",
Expand All @@ -121,8 +132,9 @@ def closure_js_template_library(
should_generate_soy_msg_defs = should_generate_soy_msg_defs,
bidi_global_dir = bidi_global_dir,
soy_msgs_are_external = soy_msgs_are_external,
compiler = compiler,
compiler = resolved_compiler,
defs = defs,
idom = idom,
)

deps = deps + [
Expand All @@ -147,20 +159,27 @@ def closure_js_template_library(
"@com_google_javascript_closure_library//closure/goog/string",
"@com_google_javascript_closure_library//closure/goog/string:const",
"@com_google_javascript_closure_library//closure/goog/uri",
"@io_bazel_rules_closure//closure/templates:soy_ve_metadata_proto",
str(Label("//closure/templates:soy_jssrc")),
]

closure_js_library(
name = name,
srcs = js_srcs,
deps = deps,
deps = deps + jsdeps + (
idom and _IDOM_DEPS or []
),
testonly = testonly,
lenient = True,
suppress = suppress + [
"analyzerChecks",
"deprecated",
"reportUnknownTypes",
"strictCheckTypes",
"unusedLocalVariables",
],
] + (idom and [
"strictModuleChecks",
"checkTypes",
] or []),
**kwargs
)
18 changes: 18 additions & 0 deletions closure/templates/soy_jssrc.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ filegroup(
"checks.js",
"jspbconversions.js",
"soydata_converters.js",
"soyutils_directives.js",
"soyutils_map.js",
"soyutils_newmaps.js",
"soyutils_templates.js",
"soyutils_usegoog.js",
],
)

filegroup(
name = "idom",
srcs = [
"api_idom.js",
"element_lib_idom.js",
"global.js",
"shim.js",
"skiphandler.js",
"soyutils_idom.js",
"soyutils_velog.js",
"types.js",
],
)
31 changes: 31 additions & 0 deletions closure/templates/soy_tslib.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2016 The Closure Rules Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

filegroup(
name = "externs",
srcs = [
"externs.js",
],
)

filegroup(
name = "tslib",
srcs = [
"tslib.js",
],
)
8 changes: 8 additions & 0 deletions closure/templates/soy_tslib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

goog.module('google3.third_party.javascript.tslib.tslib');

const tslib = goog.require(
'tslib'
);

exports = tslib;
5 changes: 5 additions & 0 deletions java/com/google/javascript/jscomp/Diagnostics.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class Diagnostics {
CheckStrictDeps.DUPLICATE_PROVIDES,
CheckStrictDeps.REDECLARED_PROVIDES,
CheckStrictDeps.NOT_PROVIDED);
DiagnosticGroups.registerGroup("generatedTypescript",
ClosureCheckModule.GOOG_MODULE_MISPLACED,
ClosureCheckModule.EXPORT_NOT_AT_MODULE_SCOPE);
}

static final DiagnosticGroups GROUPS = new DiagnosticGroups();
Expand Down Expand Up @@ -87,6 +90,7 @@ final class Diagnostics {
"externsValidation",
"extraProvide",
"extraRequire",
"generatedTypescript",
"globalThis",
"invalidCasts",
"lateProvide",
Expand Down Expand Up @@ -169,6 +173,7 @@ final class Diagnostics {
// TODO(jart): Remove these when regression is fixed relating to jscomp being able to
// identify externs files that were passed via srcs.
CheckJSDoc.INVALID_MODIFIES_ANNOTATION,
ReplaceIdGenerators.NON_GLOBAL_ID_GENERATOR_CALL,
CheckJSDoc.INVALID_NO_SIDE_EFFECT_ANNOTATION);

static final ImmutableMap<String, DiagnosticType> DIAGNOSTIC_TYPES = initDiagnosticTypes();
Expand Down